As of the release of the next stable AngularJS, I am migrating my application from version 1.0.8 to 1.2.
In AngularJS 1.0.8 it was possible to set up an isolated scope for directives like follow
. The directive would then use its own test()
function instead of the controller's test()
function.
HTML
<my-dialog property="something">
<button ng-click="test()">Load Test</button>
Check out the test: "{{ testMessage }}"
</my-dialog>
Javascript
.controller('Ctrl', function(scope) {
scope.test = function () {
scope.testMessage = 'CTRL Test loaded! Whooops.';
}
})
.directive('myDialog', function() {
return {
restrict: 'E',
scope: {
property: '='
},
link: function(scope) {
scope.test = function () {
scope.testMessage = 'Isolated Test loaded. Yes!';
}
}
};
In AngularJS 1.2 this behavior doesn't work anymore. Clicking the button fires the controller's test()
function now.
See this jsFiddle comparison:
What exactly has changes and how can I reproduce the old behavior?
Note
I figured out I could place the directives template inside an extra HTML file or compile it as a string to get it working (jsFiddle) but it seems to be too much in my case, as the template is fixed and splitting the HTML over several partial HTML files is a hassle.
EDIT
@elclanr's answer works fine when there are no other properties to share. I updated the jsFiddle to pass some arbitrary property. How should I proceed now?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…