I am experimenting with AngularJS 1.3 (I just migrated my app from 1.2). I am playing with the new one-time binding. I have come across this case where it is not working, can someone please explain why? I am dynamically generating an id field by calling a method within the view. As a result, the one-time binding does not seem to be working. See http://plnkr.co/edit/GyfKKb?p=preview.
Specifically, I'm expecting the one-time to not re-render the ng-repeat when a new element is added to the array. But pushing a new element into the array (via button click) also makes the new element appear in the output of the ng-repeat.
index.html
<body ng-controller="MainCtrl">
<!-- TODO: I would expect addItemC() to do nothing with one time binding -->
<button ng-click="addItemC()">add</button>
<div ng-repeat="itemC in ::itemsC">
<!-- dynamically generate id that is cause breakage -->
{{::itemC.id() | limitTo:3}}
</div>
</div>
app.js
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
// generate random string id dynamically (code taken from stackoverlow answer)
var itemObj = {
id: function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 100; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
};
// one time binding does not work
$scope.itemsC = [
angular.copy(itemObj),
angular.copy(itemObj),
angular.copy(itemObj)
];
$scope.addItemC = function() {
$scope.itemsC.push(angular.copy(itemObj));
}
});