I thought I'd mastered isolated scopes with custom directives, then hit this problem, which I've been struggling with for 3 hours now:
Once the isolated scope is created for the directive I thought you could set any scope data (in this case greeting) within the controller or link function. But referencing {{greeting}} in the HTML doesn't work, even though greeting it is shown in the scope when inspected via the console?
I thought the new isolated scope would be assigned to the directive myDir and than anything defined on that scope would be accessible within the HTML contents of <my-dir>. Obviously, I have a gap in understanding.
Any ideas please?
Plunker: here
HTML:
<my-dir>
Greeting: {{greeting}}
</my-dir>
JS:
var app = angular.module('myApp', []);
app.directive('myDir', function() {
return {
restrict: 'EA',
scope: {},
controller: ['$scope', function ($scope) {
$scope.greeting = 'Hello';
//this.greeting = 'Hello';
}],
link: function(scope, element, attrs){
//scope.greeting = 'Hello';
}
};
})
replace
scope: {}withthat's not possible the current dom belongs to parent so it will consider only parent scope directice's isolated scope will not work.