Reputation: 301
I am working on angular js project to make todolist application.But I am stuck at place where I Want to add my todo details to todoList but I am getting error.
Requrirement to declare property in adddetails and then call service method save item to add todo details to service list
Here is my code:
Error getting is
KNode.js (linux; U; rv:v8.15.1) AngularJS Unit Test should call saveitem method of service while adding new item FAILED
ReferenceError: Myservice is not defined at Object.$scope.saveitem (app/scripts/controllers/main.js:9:619) at UserContext. (test/spec/controllers/main.js:118:12)
Node.js (linux; U; rv:v8.15.1): Executed 13 of 16 (1 FAILED) (0 secs / 0.064 secs)
[1A[2KNode.js (linux; U; rv:v8.15.1) AngularJS Unit Test should display the selected item when clicked on edit button FAILED
Expected spy getitem to have been called with [ 1 ] but it was never called. at UserContext. (test/spec/controllers/main.js:148:17)
Expected [ Object({ id: 0, name: '', age: 0, mobile: 0 }) ] to equal Object({ name: 'one', age: 2, mobile: 3333333333, id: 1 }). at UserContext. (test/spec/controllers/main.js:149:30)
Node.js (linux; U; rv:v8.15.1): Executed 14 of 16 (2 FAILED) (0 secs / 0.07 secs)
[1A[2KNode.js (linux; U; rv:v8.15.1) AngularJS Unit Test should update the arraylist after edit & save FAILED
ReferenceError: Myservice is not defined at Object.$scope.saveitem (app/scripts/controllers/main.js:9:619) at UserContext. (test/spec/controllers/main.js:191:12)
Node.js (linux; U; rv:v8.15.1): Executed 15 of 16 (3 FAILED) (0 secs / 0.074 secs)
[1A[2KNode.js (linux; U; rv:v8.15.1) AngularJS Unit Test should delete the selected item when clicked on delete button FAILED
Expected spy deleteitem to have been called with [ 1 ] but it was never called. at UserContext. (test/spec/controllers/main.js:238:17)
Expected 3 to be 2. at UserContext. (test/spec/controllers/main.js:239:45)
Expected 1 to be 2. at UserContext. (test/spec/controllers/main.js:241:42)
Expected Object({ name: 'two', age: 2, mobile: 2222222222, id: 2 }) to be undefined. at UserContext. (test/spec/controllers/main.js:242:39)
Expected $.length = 3 to equal 2.
Expected $[1].name = 'one' to equal 'two'.
Expected $[1].age = 1 to equal 2.
Expected $[1].mobile = 3333333333 to equal 2222222222.
Expected $[1].id = 1 to equal 2.
Expected $[2] = Object({ name: 'two', age: 2, mobile: 2222222222, id: 2 }) to equal undefined. at UserContext. (test/spec/controllers/main.js:243:36)
Node.js (linux; U; rv:v8.15.1): Executed 16 of 16 (4 FAILED) (0 secs / 0.079 secs)
[1A[2KNode.js (linux; U; rv:v8.15.1): Executed 16 of 16 (4 FAILED) (0.104 secs / 0.079 secs)
index.js
var myApp = angular.module('myApp', []);
// define controller here
myApp.controller('MainController',["$scope", 'MyService', function($scope,MyService) {
$scope.init = function () {
MyService.list();
}
$scope.adddetail = [
{
id:0,
name:'',
age:0,
mobile:0,
} ];
// define "init" function
// call 'list' method of service
// define "adddetail" property
$scope.saveitem = function () {
Myservice.saveitem();
}
$scope.edititem = function () {
}
$scope.deleteitem = function () {
}
// define "saveitem" function
// call 'saveitem' method of service
// clear ng-model after saved
// define "edititem" function
// call 'getitem' method of service
// define "deleteitem" function
// call 'deleteitem' method of service
// call "init" function
}]);
// 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
});
Upvotes: 0
Views: 597
Reputation: 3618
As you can see here:
ReferenceError: Myservice is not defined
at Object.$scope.saveitem (app/scripts/controllers/main.js:9:619)
error caused by a typo(MyService is the correct service name):
$scope.saveitem = function () {
MyService.saveitem();
}
Upvotes: 1