0

Local Storage を使用して AngularJS プロジェクトに取り組もうとしています。todoリストアプリを作って、それぞれのtodoノートを を使って保存していangular-local-storageます。localStorageServiceコントローラーで使用する を作成しました。app.js にサービスを依存関係として挿入しましたが、空白のページとコンソール エラーが表示され続けます: Uncaught Error: No module: LocalStorageModule. 構文に何か問題がありますか??... または、サービスの使い方が間違っていますか?

app.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 に答える