The issue arises from the fact that the
my-params="{title: 'this is title'}"
is considered a
constant expression and cannot be changed. Therefore, any attempt to modify the value of the
'title'
property will be overridden by the constant itself. You can see an example of this behavior in
this code snippet, which demonstrates how Angular 1.4 handles directives with constant expressions compared to dynamic values from a controller:
<div ng-app="app" ng-controller="Ctrl as ctrl">
<div my-directive my-params="{title: 'this is title'}"></div>
<div my-directive my-params="data"></div>
</div>
In the second instance where a non-constant expression is used, it works as expected.
If you switch the Angular version to 1.2, you will notice that Angular throws an error related to infinite digest cycle:
VM1033 angular.js:9101 Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
Watchers fired in the last 5 iterations: [["fn: parentValueWatch; newVal: {\"title\":\"this is title\"}; oldVal: {\"title\":\"this is title\"}"],["fn: parentValueWatch; newVal: {\"title\":\"this is title\"}; oldVal: {\"title\":\"this is title\"}"],["fn: parentValueWatch; newVal: {\"title\":\"this is title\"}; oldVal: {\"title\":\"this is title\"}"],["fn: parentValueWatch; newVal: {\"title\":\"this is title\"}; oldVal: {\"title\":\"this is title\"}"],["fn: parentValueWatch; newVal: {\"title\":\"this is title\"}; oldVal: {\"title\":\"this is title\"}"]]
This problem occurs because the expression within the directive (
my-params="{title: 'this is title'}"
) attempts to overwrite the scope attribute of the directive continuously (creating new objects in Angular 1.2, resulting in an infinite digest loop).