AngularJS not refreshing ngRepeat when updating array

You are modifying the scope outside of angular’s $digest cycle 50% of the time. If there is a callback which is not from angularjs; (posibbly jquery). You need to call $apply to force a $digest cycle. But you cannot call $apply while in $digest cycle because every change you made will be reflected automatically already. … Read more

Angular.js ng-switch-when not working with dynamic data?

From the docs — Be aware that the attribute values to match against cannot be expressions. They are interpreted as literal string values to match against. For example, ng-switch-when=”someVal” will match against the string “someVal” not against the value of the expression $scope.someVal. So in other words, ng-switch is for hardcoding conditions in your templates. … Read more

Angular ng-repeat with ng-form, accessing validation in controller

Updated 2015-01-17: As pointed out by Leblanc Meneses in the comments Angular 1.3 now supports interpolation with form, ngForm and input directives. This means that using expressions to name your elements: <div ng-form=”namesForm_{{$index}}” ng-repeat=”name in names”> <input type=”text” name=”input_{{$index}}_0″></input> <!– … –> </div> will work as expected: $scope[‘namesForm_0’] $scope.namesForm_1 // Access nested form elements: $scope.namesForm_1.input_1_0 … Read more

how to use animation with ng-repeat in angularjs

Following on from Marcel’s comment: in AngularJS 1.2 you don’t need to use the ng-animate directive. Instead: Includeangular-animate[-min].js. Make your module depend on ngAnimate. Define your transitions in CSS using classes like .ng-enter and .ng-enter-active. Use ng-repeat as you normally would. HTML: <div ng-app=”foo”> <!– Set up controllers etc, and then: –> <ul> <li ng-repeat=”item … Read more

Angular orderBy number sorting as text in ng-repeat

I think the most appropriate solution is to format the numbers I have on my JSON objects correctly, ie not to wrap them in quotes. So: [{“id”:”42″,”firstname”:”Sarah”,”lastname”:”Dilby”,”age”:”40″,”cars”:”Yaris”}, {“firstname”:”Jason”,”lastname”:”Diry”,”age”:”5″,”id”:”5″}, {“id”:”6″,”firstname”:”Bilson”,”lastname”:”Berby”,”age”:”1″,”cars”:”Tipo”}] becomes: [{“id”:42,”firstname”:”Sarah”,”lastname”:”Dilby”,”age”:40,”cars”:”Yaris”}, {“firstname”:”Jason”,”lastname”:”Diry”,”age”:5,”id”:5}, {“id”:6,”firstname”:”Bilson”,”lastname”:”Berby”,”age”:1,”cars”:”Tipo”}] I’m guessing SergL’s solution is good if it’s not possible to correct the format of the JSON data. To add to this, … Read more

AngularJS: ng-repeat with dynamic list, without rebuilding entire DOM tree?

For those finding this from google, the page below describes a feature in AngularJS 1.2 that helps with this problem: http://www.bennadel.com/blog/2556-Using-Track-By-With-ngRepeat-In-AngularJS-1-2.htm Edit to add: The most important sentences from the linked post, in case the link ever dies: With the new “track by” syntax, I can now tell AngularJS which object property (or property path) … Read more

Does ngRepeat exist in Angular 2?

Angular 2.0 Release my-component.ts: import { Component } from ‘angular2/core’; @Component({ selector: ‘my-component’, templateUrl: ‘./my-component.html’ }) export class MyComponent{ public values: number[] = [1, 2, 3]; } my-component.html: <div *ngFor=”let value of values; trackBy: index;”> {{ value }} </div>

Angularjs OrderBy on ng-repeat doesn’t work

$scope.teams isn’t an array (it’s an object of objects), and the orderBy filter only works with arrays. If you make $scope.teams an array, it will work: $scope.teams = [ { id: 100, name: “team1”, count_win: 3, count_loose: 2, goal_average: 2, }, { id: 200, name: “team2”, count_win: 3, count_loose: 2, goal_average: 1, }, { id: … Read more