Without calling the communication function, there is no two-way data binding between the template created by the compilation function and the scope.
, link, .
angular docs. , .
HTML :
$ DOM .
, , , DOM. .
, DOM, , .
. DOM. . "" , .
$compile , . , , , $watchs , .
DOM. , DOM.
EDIT CODE:
compile link,
EDIT CODE 2:
.directive('myDirective', function () {
console.log('My Directive Called');
return {
restrict: 'E',
scope: {
localVar: '@color'
},
template : '<span> {{ localVar }} </span>'
};
});
HTML:
<my-directive color='purple'>
</my-directive>
3:
directive('myDirective', function () {
console.log('My Directive Called');
return {
restrict: 'EA',
template: '<span>{{ localVar }}</span>',
compile: function (tElement, tAttrs) {
return {
post: function postLink(scope, iElement, iAttrs, controller) {
scope.localVar = 'red';
}
}
}
};
})