Nested directives

363 views
Skip to first unread message

nidi nidi

unread,
Mar 26, 2012, 4:25:08 AM3/26/12
to ang...@googlegroups.com
Hi all

Trying out templating with directive, I used a directive inside a template and set its value dynamically:

.directive('dyn', function(){
return{
template:'<div content="{{param}}"></div>{{param}}',
restrict:'E',
scope:{param:'attribute'}
};

.directive('content',function(){
return function(scope,element,attrs){
element.text('content: '+attrs.content);
};
})

inside 'content' attrs.content is undefined. I expected it to be the value of 'param'

see http://jsfiddle.net/CkWWm/1/

Is this not supposed to work or did I do something wrong?

thanks a lot
nidi

Peter Bacon Darwin

unread,
Mar 26, 2012, 4:45:56 AM3/26/12
to ang...@googlegroups.com
The problem is with your content directive: http://jsfiddle.net/CkWWm/2/.  You can see that  <div content="{{val}}"></div> is not binding to $scope.val correctly in the simple case so it has no change in the nested case.
Pete

nidi

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.


Peter Bacon Darwin

unread,
Mar 26, 2012, 5:00:44 AM3/26/12
to ang...@googlegroups.com
Hi nidi
I managed to hack around with the scoping and got it working but it might not be quite what you want as now the parameters are expected to be evaluated and so if you want a static string then you have to add quotes: http://jsfiddle.net/CkWWm/3/
Pete

Peter Bacon Darwin

unread,
Mar 26, 2012, 5:01:33 AM3/26/12
to ang...@googlegroups.com

stefan niederhauser

unread,
Mar 26, 2012, 6:01:38 AM3/26/12
to ang...@googlegroups.com

Hi Pete

 

Thanks for the solution. This works perfectly for me.

Reply all
Reply to author
Forward
0 new messages