0

我正在尝试使用本地存储处理 AngularJS 项目。我正在制作一个待办事项列表应用程序并使用angular-local-storage. 我做了一个localStorageService在我的控制器中使用的。我已将该服务作为依赖项注入到我的 app.js 中,但是我不断收到空白页和控制台错误:Uncaught Error: No module: LocalStorageModule. 我的语法有什么问题吗??...还是我错误地使用了我的服务?

应用程序.coffee

@angTut = angular.module("angTut", ['LocalStorageModule']);

@angTut.config(["$routeProvider", ($routeProvider) ->
$routerprovider = $routeProvider;
$routeProvider.when("/",
    templateUrl: "views/Pages/welcome.html"
    controller: "PagesController"
);
$routeProvider.when("/add",
    templateUrl: "views/Todos/add.html"
    controller: "TodosController"
);
$routeProvider.otherwise(
    redirectTo: "/"
);
])

todo_controller.coffee

"use strict"
@angTut.controller('TodosController', (
$scope
todoService
) ->
$scope.save = ->
    todoService.add($scope.note)
    $scope.list()

$scope.clear = ->
    todoService.clear()
    $scope.list()

$scope.list = ->
    $scope.notes = []
    storedNotes = todoService.get(true)
    if storedNotes?
        i = 0
        while i < storedNotes.length
          $scope.notes.push storedNotes[i]
          i++

)

todo_service.coffee

'use strict'
@angTut.service('todoService', (
localStorageService
) ->
addFn = (data) ->
    existingValue = getFn();
    if(existingValue isnt null)
        newData = existingValue + ',' + data
        localStorageService.add('someStorageKey', newData)
    else
        localStorageService.add('someStorageKey', data)
    return data

getFn = (returnAsArray) ->
    storedNotes = localStorageService.get('someStorageKey')
    if storedNotes? and returnAsArray
        return storedNotes.split(',')
    else
        return storedNotes

clearFn = ->
    localStorageService.clearAll()

add: addFn
get: getFn
clear: clearFn
)
4

2 回答 2

1

I am certain it has to do with how you referenced the dependency in your bower.json. The name of this component isn't exactly as the project name on github. It's possible the bower component was recently renamed but I'm not very sure about that. If you try searching for the component with the project name;

bower search angular-local-storage

No results.

I believe the name of the component you intend to use is 'angular-localstorage'.

☺  bower search angular-localstorage                                                                       ruby-2.0.0-p247
Search results:

angular-localstorage git://github.com/grevory/angular-local-storage.git

If that is the case, then make the necessary changes to make sure you're referencing it right in your 'bower.json' file.

E.g

"dependencies": {
  ...
  "angular-localstorage": "*"
}

Don't forget to name it right in your view as well.

Note that the actual Javascript file is still 'angular-local-storage.js'

E.g.

<script src="components/angular-localstorage/angular-local-storage.js"></script>

于 2013-10-10T09:13:13.277 回答
0

并非如此,该模块确实存在于名称为

angular-local-storage git://github.com/grevory/angular-local-storage.git
于 2014-11-11T12:43:53.203 回答