我正在尝试使用本地存储处理 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
)