How to bind scope from attrs.$observe?
<test func="hohoho"></test>
app.directive('test', function(){
return {
restrict: 'E'
, scope: { parentFunc: '@func'}
, link: function(scope, element, attrs) {
var func = '';
attrs.$observe('func', function(val) {
func = val;
console.log(func);
})
console.log('end');
console.log(func);
console.log(scope.parentFunc);
});
}
};
});
when i run, it will print
end
undefined
undefined
(an empty string)
hohoho
why i get undefined when i print func and parentFunc?