ngNode directive helper

36 views
Skip to first unread message

Gabriel Aszalos

unread,
May 31, 2014, 5:49:00 PM5/31/14
to ang...@googlegroups.com
I have developed a 314 byte helper service to help access HTML Elements on template from within directives easier. Inspired from Dojo's "data-dojo-attach-point". Feedback is appreciated :)

Daphne Maddox

unread,
Jun 1, 2014, 4:21:33 AM6/1/14
to ang...@googlegroups.com
This is interesting.  I'm trying to decide how I feel about it -- you're granting the parent directive the role of coordinating arbitrary child elements. I think I like it but something is nagging at me. It might take me a little while to put my finger on it. In your example, you don't show it using transclusion, is that right?

Gabriel Aszalos

unread,
Jun 1, 2014, 5:34:57 AM6/1/14
to ang...@googlegroups.com
Thanks Daphne! While I also agree this is very interesting it is also very flawed. It only just came to my attention that in a scenario where, for example, you would have a button directive with an ng-node in its template, that is used in multiple places in the same view would break the service due to multiple ng-nodes having the same name in the same view. 

It would be nice if there was a clean way to bind $node exclusively to its parent directive, but I doubt there is. The only way would be to add it into Angular itself. To me it feels that something like this would be very handy and would make code nicer, cleaner, easier to manage and faster. 
--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/Elos01C9ftI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Daphne Maddox

unread,
Jun 1, 2014, 6:49:44 AM6/1/14
to ang...@googlegroups.com

Well, sharing the scope of the parent using normal directive techniques is still an option and doesn't require element navigation. Plus, it maintains the separation of presentation from scopes (in this case directive scope rather than controller scope). It was that against which I was evaluating ngNode. NgNode seemed interesting as more of a one-off composite-maker trick. As you point out the implementation has a flaw, but the larger question might be whether there is some way to do shorthand for one-off composite directives, or whether the existing options are at about the right level with respect to required effort to connect the pieces.

Reply all
Reply to author
Forward
0 new messages