Angular: problem with one-time binding
One-time binding always seems to make a copy, whereas a normal binding will make a reference comparison of objects. This Fiddle shows this by putting a reference to $scope in a watched object.
by Michiel Helvensteijn
June 19, 2014
HTML
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-beta.13/angular.min.js"></script>
<div ng-controller="myController">
<my-directive my-attr="obj"></my-directive> <!-- normal binding: OK -->
<my-directive my-attr="::obj"></my-directive> <!-- one-time binding: Error (because a copy is made) -->
</div>
JavaScript
var myApp = angular.module('myApp',[]);
myApp.directive('myDirective', function() {
return {
restrict: 'E',
template: '<span style="color: red">{{ myAttr.message }}</span>',
scope: { myAttr: '=' }
};
});
myApp.controller('myController', ['$scope', function ($scope) {
$scope.obj = {
message: 'hello',
scope: $scope
};
}]);