I have a list of objects in my scope and you want to iterate over them, show some of their properties in the order ordered by properties and change them.
ng-repeat is used to display text fields attached to each object of my list, and an ordering filter that takes a "position" as a parameter.
Once again, the position is also editable!
Now we change the position of a certain object once (angular reorders the list as expected), and then we change it twice. Angular does not reorder the list.
Can someone explain how to correct this situation only after registration and what are the reasons for this behavior?
Here is the fiddle: JSFiddle
HTML
<div ng-controller="MyCtrl"> <p>List of activities:</p> <div ng-repeat="activity in model.activities | orderBy: 'position'"> <textarea type="text" ng-model="activity.name"> </textarea> {{activity.name}} <input type="text" ng-model="activity.position"> </div> </div>
Js
var myApp = angular.module('myApp',[]); function MyCtrl($scope) { $scope.model = { activities: [ {name: "activity 1", position: 1}, {name: "activity 2", position: 2}, {name: "activity 3", position: 3}, {name: "activity 4", position: 4}, {name: "activity 5", position: 5} ] }; }
javascript angularjs angularjs-orderby angularjs-model
Ilia Syrtsou
source share