Angular.js - 范围连接错误

时间:2014-06-27 21:55:30

标签: angularjs angularjs-scope

我在向todo list app添加用户模型时遇到问题:

http://yeoman.io/codelab/write-app.html

这是我的控制器:

'use strict';

 angular.module('test3App')
.controller('MainCtrl', function ($scope, localStorageService) {

var usersInStore = localStorageService.get('users');
var todosInStore = localStorageService.get('todos');


$scope.users = usersInStore && usersInStore.split('\n') || [];
$scope.todos = todosInStore && todosInStore.split('\n') || [];

$scope.$watch('users', function () {
  localStorageService.add('users', $scope.users.join('\n'));
}, true);

$scope.$watch('todos', function () {
  localStorageService.add('todos', $scope.todos.join('\n'));
}, true);


$scope.addTodo = function () {
  $scope.todos.push($scope.todo);
  $scope.todo = '';
};

$scope.removeTodo = function (index) {
  $scope.todos.splice(index, 1);
};

 $scope.addUser = function () {
  $scope.users.push($scope.users);
  $scope.users = '';
};

$scope.removeUser = function (index) {
  $scope.users.splice(index, 1);
}; });

我在这一行收到错误:

  localStorageService.add('users', $scope.users.join('\n'));

  TypeError: undefined is not a function
  at Object.fn (http://localhost:9000/scripts/controllers/main.js:14:53)
  at Scope.$digest (http://localhost:9000/bower_components/angular/angular.js:12251:29)
  at Scope.$apply (http://localhost:9000/bower_components/angular/angular.js:12516:24)
  at HTMLFormElement.<anonymous>       (http://localhost:9000/bower_components/angular/angular.js:18626:21)
at HTMLFormElement.jQuery.event.dispatch (http://localhost:9000/bower_components/jquery/dist/jquery.js:4641:9)
at HTMLFormElement.elemData.handle (http://localhost:9000/bower_components/jquery/dist/jquery.js:4309:46) 

我做错了什么?

0 个答案:

没有答案