Javascript 如何在angular js中将todo详细信息添加到我的todo列表
我正在开发angular js项目来制作todolist应用程序。但我一直停留在想将我的todo细节添加到todolist的地方,但我遇到了错误 要求在adddetails中声明属性,然后调用服务方法save item将todo详细信息添加到服务列表中 这是我的密码: 获取信息时出错 KNode.jslinux;Urv:v8.15.1 AngularJS单元测试应在添加新项失败时调用服务的saveitem方法 ReferenceError:未定义Myservice 位于Object.$scope.saveitem app/scripts/controllers/main.js:9:619 在UserContext。test/spec/controllers/main.js:118:12 Node.jslinux;Urv:v8.15.1:执行16 1中的13 1 0秒/0.064秒失败 [1A[2KNode.js linux;U;rv:v8.15.1 AngularJS单元测试在单击编辑按钮失败时应显示所选项目 应使用[1]调用spy getitem,但从未调用它。 在UserContext.test/spec/controllers/main.js:148:17 预期[Object{id:0,name:,age:0,mobile:0}]等于Object{name:'1',age:2,mobile:3333,id:1}。 位于UserContext.test/spec/controllers/main.js:149:30 Node.js linux;U;rv:v8.15.1:执行16个中的14个2失败0秒/0.07秒 [1A[2KNode.js linux;U;rv:v8.15.1 AngularJS单元测试应在编辑和保存失败后更新arraylist ReferenceError:未定义Myservice 位于Object.$scope.saveitem app/scripts/controllers/main.js:9:619 在UserContext.test/spec/controllers/main.js:191:12 Node.js linux;U;rv:v8.15.1:执行16 3中的15 3次失败0秒/0.074秒 [1A[2KNode.js linux;U;rv:v8.15.1 AngularJS单元测试在单击删除按钮失败时应删除所选项目 应使用[1]调用spy deleteitem,但从未调用它。 在UserContext.test/spec/controllers/main.js:238:17 预计3是2。 在UserContext.test/spec/controllers/main.js:239:45 1应该是2。 位于UserContext.test/spec/controllers/main.js:241:42 预期对象{name:'two',age:2,mobile:2222,id:2}未定义。 在UserContext.test/spec/controllers/main.js:242:39 预期$.length=3等于2 应为$[1]。名称='one'等于'two' 应为$[1]。年龄=1等于2 应为$[1]。mobile=3333等于2222 应为$[1]。id=1等于2 预期$[2]=对象{name:'two',age:2,mobile:2222,id:2}等于未定义。 位于UserContext.test/spec/controllers/main.js:243:36 Node.js linux;U;rv:v8.15.1:执行16/16 4失败0秒/0.079秒 [1A[2KNode.js linux;U;rv:v8.15.1:执行16次,共4次失败0.104秒/0.079秒 index.js 正如你在这里看到的: ReferenceError:未定义Myservice 位于Object.$scope.saveitem app/scripts/controllers/main.js:9:619 TypeMyService导致的错误是正确的服务名称:Javascript 如何在angular js中将todo详细信息添加到我的todo列表,javascript,angularjs,Javascript,Angularjs,我正在开发angular js项目来制作todolist应用程序。但我一直停留在想将我的todo细节添加到todolist的地方,但我遇到了错误 要求在adddetails中声明属性,然后调用服务方法save item将todo详细信息添加到服务列表中 这是我的密码: 获取信息时出错 KNode.jslinux;Urv:v8.15.1 AngularJS单元测试应在添加新项失败时调用服务的saveitem方法 ReferenceError:未定义Myservice 位于Object.$scope
$scope.saveitem = function () {
MyService.saveitem();
}
// define MyService here
myApp.service('MyService', function () {
//unique id
var uid = 1;
//arraylist to hold all items
var arraylist;
this.arraylist = [{
id: 0,
'name': 'Rahul',
'age': 21,
'mobile': 8866774455
}];
this.saveitem = function () {
if($scope.arraylist === undefined){
return false ;
}
else{
$scope.todoObj = {};
$scope.todoObj["uid"] = $scope.todo;
$scope.todolist.push($scope.todoObj);
$scope.arraylist = [];
}
}
this.getitem= function () {
}
this.deleteitem= function () {
}
this.list= function () {
}
// define 'saveitem' function
// add a new item in arraylist (hint: add new item with id)
// update existing item from arraylist (hint: edit existing item by id)
// define 'getitem' function
//get particular item by id from arraylist
// define 'deleteitem' function
// delete selected item from arraylist
// define 'list' function
// return arraylist
});
$scope.saveitem = function () {
MyService.saveitem();
}