i am trying to find out when and how to use the link function in angular directives.
Say i have the following directive:
app.directive("lbArticle", function() {
return {
restrict : "E",
templateUrl: 'tpl/directives/information/article.html',
scope: {
article: '='
},
link: function(scope,element, attr){
scope.info = attr.article;
}
};
});
Now passing an object to the article attachment of the HTML
<lb-article article='{{myObject}}'> </lb-article>
When this happens and the directive is rendered it should set a variable called info equal to myObject
So if myObject looked like this:
myObject{name: 'Hello', created: '2015-04-04'; }
Then the following should display these variables:
my directive html
<span class="block text-ellipsis">{{info.name}}</span>
<small class="text-muted">{{info.created | fromNow}}</small>
However this does not work?
As far as i can read for the documentation the link function should be used for DOM manipulation and also for setting variables that might be rendered before the actual directive?
scope.info = attr.article;has no real use, as you already havearticlein that scope