Hi Sander, If you need to rest please do it.... we can continue this conversation another day.
The reason for the transclude is the replaceWith of the base element of the directive. The directive replace the custom element <dropdown> with valid markup. I thought that was pretty the point of angularjs, i.e the ability to extend html. I dont know how to split that in 2, I never made directives that communicate with each other, and also I did not get to read about it. at this stage the purpose of this directive is rather simple. It is a replacement for the html element <select>. The only additional feature compared to a <select> is that it can have html with the <option> element instead of text. Later I will add more features, like a search field. So now, I think the logic in it can be simply described. There is 2 parts : 1. translate the custom markup to valid markup. 2. handle interactivity (show/hide of the options and click-to-select) I guess the stuff that feels weird to you are rather located in the part 1: a. The attributesToString() function is used to copy the attributes of the original element <dropdown> to the replacement element, a <span>. I did not knew any angularjs prescription about this, but I thought it would be nice if the directive let developer that use it add their attributes if they need to, for whatever reasons. b. The angular.forEach loop copies the <option> contents and values to a <li> collection and sets the default value in the top <span>. c. Stuff mades in steps (a) and (b) are populated into the html structure, and then compiled with $compile to give angular knowledge of the event handlers in it. part 2: just 2 methods show() and select() to respectively show the list and select an item in it. What are the parts that appear to you as fragile ? -olivier On Wed, Jan 22, 2014 at 7:25 PM, Sander Elias <[email protected]> wrote: > Hi Olivier, > > I don't have the steam to work it out now, But why did you do the entire > construct like that it looks overly complicated and fragile to me? > Don't see a reason for the transclude. > How about splitting it in 2? > 1 dropdown directive, that hold the logic for the list, and the > entry-point. > 2. a couple of dropdown-item directives, that handles their own, and > require the dropdown to register there? > > Regards > Sander > > > > -- > You received this message because you are subscribed to the Google Groups > "AngularJS" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/angular. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "AngularJS" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/angular. For more options, visit https://groups.google.com/groups/opt_out.
