Recently, I started incorporating Angular 1.2.0 into my development application and encountered an issue with a particular function not working as expected:
var myItems = angular.model('myItems', []);
myItems.controller('itemsController', function($scope, $http) {
// delete item from the database
$scope.deleteItem = function(id) {
$http.delete('/api/items/' + id)
.success(function(data) {
$scope.items = data;
})
.error(function(data) {
// log error
});
};
});
This is how I trigger the deletion of an item in my view:
<input type="checkbox" data-ng-click="deleteItem(item._id)"> {{ item.text }}
Since I am relatively new to Angular, I am unsure about what might be causing this issue. I checked the changelog for version 1.2 on the Angular repository, but could not find a solution. Could someone experienced with Angular help me understand the problem here?
Edit: Upon inspecting the Chrome error console, I noticed an error message that appears when the page loads. Despite clicking on the checkbox to delete an item, nothing happens.
Error: [$parse:isecprv] http://errors.angularjs.org/undefined/$parse/isecprv?p0=deleteItem(item._id)
at Error (<anonymous>)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:6:453
at ha (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:84:103)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:87:372
at Array.forEach (native)
at q (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:7:261)
at rc (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:87:354)
at Jb.readIdent (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:149:31)
at Jb.lex (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:144:199)
at Ya.parse (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:151:12) <input type="checkbox" data-ng-click="deleteItem(item._id)">
Update: It appears that one of the recent changes introduced in Angular 1.2.0-rc2 (current stable build) involves private properties within the scope chain. This change potentially impacts applications utilizing document-oriented databases like MongoDB
, leading to issues like the one I encountered. If you are facing a similar problem, consider reverting to version 1.2.0-rc3 or adopt the recommended approach of encapsulating sensitive APIs in a closure/controller as stated in the changelog.