How to ‘unwatch’ an expression

To have a repeater with a large array that you don’t watch to watch every item. You’ll need to create a custom directive that takes one argument, and expression to your array, then in the linking function you’d just watch that array, and you’d have the linking function programmatically refresh the HTML (rather than using … Read more

How do I filter an array with AngularJS and use a property of the filtered object as the ng-model attribute?

You can use the “filter” filter in your controller to get all the “C” grades. Getting the first element of the result array will give you the title of the subject that has grade “C”. $scope.gradeC = $filter(‘filter’)($scope.results.subjects, {grade: ‘C’})[0]; http://jsbin.com/ewitun/1/edit The same with plain ES6: $scope.gradeC = $scope.results.subjects.filter((subject) => subject.grade === ‘C’)[0]

Angularjs ui-router abstract state with resolve

Solution here is to distinguish the names of the resolved data. Check this answer: angular ui-route state parent and resolve (nested resolves) And its plunker So in our case we would need this change in parent resolve: { dataParent: [‘$stateParams’, ‘ProfileService’, function ($stateParams, ProfileService) { var username = $stateParams.username; return ProfileService.getProfile(username); }] } and this … Read more

AngularJS: Uncaught Error: [$injector:modulerr] Failed to instantiate module?

Try using No Wrap – In Head or No wrap – in body in your fiddle: Working fiddle: http://jsfiddle.net/Q5hd6/ Explanation: Angular begins compiling the DOM when the DOM is fully loaded. You register your code to run onLoad (onload option in fiddle) => it’s too late to register your myApp module because angular begins compiling … Read more

AngularJS Service Passing Data Between Controllers

Define your service like this app.service(‘userService’, function() { this.userData = {yearSetCount: 0}; this.user = function() { return this.userData; }; this.setEmail = function(email) { this.userData.email = email; }; this.getEmail = function() { return this.userData.email; }; this.setSetCount = function(setCount) { this.userData.yearSetCount = setCount; }; this.getSetCount = function() { return this.userData.yearSetCount; }; }); Check out Duncan’s answer here: … Read more

AngularJS $http vs service vs ngResource

Decided I’ll formulate this into an answer since in the comments we worked out basically what you wanted to know: Using $http or $resource the results can still be cached, you pointed out the reasons to use one over the other really in your question. If you have a RESTful interface then using $resource is … Read more

How to set scope property with ng-init?

You are trying to read the set value before Angular is done assigning. Demo: var testController = function ($scope, $timeout) { console.log(‘test’); $timeout(function(){ console.log($scope.testInput); },1000); } Ideally you should use $watch as suggested by @Beterraba to get rid of the timer: var testController = function ($scope) { console.log(‘test’); $scope.$watch(“testInput”, function(){ console.log($scope.testInput); }); }