Another thing I do once in a great while if I have a lot of different render templates in a single directive and they're all kind of complicated is use ng-include.
<div ng-include="item.type + '.html'"></div> would (I think) work. Here's a plunk: http://plnkr.co/edit/F0ZQjv?p=preview Of course this does funny stuff with scopes and stuff. Most of the time if you're getting this funky, you probably want to make different directives for each type or something. This worked for me in a very specific context: I was displaying a list of interface events to the user, kind of like a facebook event feed. Lots of different ways to say, "that happened" - Bob replied to your post, Joe liked your reply to bob's post, and so on. I wrote a generic <show-event evt="event"> directive that did some introspection on the event itself to select a template to display. We started by using ng-if, moved to ng-switch, but then ended up with the ng-include approach mostly for coder sanity. It is a lot easier sometimes to know you're looking at 15 different mutually exclusive templates, each at the same level of the DOM, than it is to have a single very long <ng-if> stack. But that's probably mostly a matter of: what works best for you. e On Fri, Sep 26, 2014 at 10:56 AM, Mark Volkmann <[email protected]> wrote: > I think that's fine, but you may want to use ng-switch instead of ng-if. > > On Fri, Sep 26, 2014 at 12:50 PM, Evgeny Nepomnyashchiy < > [email protected]> wrote: > >> Hello guys, >> >> I'm newbie in Angular JS, I have very simple question: >> I use ng-repeat directive for showing list of data. View of each item >> depends on data, I want to use different views for different types of data. >> I use ng-if directive like this: >> >> <div ng-repeat="item in items"> >> <div ng-if="item.type == 1"> >> Type 1 >> </div> >> <div ng-if="item.type == 2"> >> Type 2 >> </div> >> <div ng-if="item.type == 3"> >> Type 3 >> </div> >> ... >> </div> >> >> Is it good practice? What can you suggest me to use? How is it from >> performance perspective? >> >> Thank you! >> Have a nice weekend! >> >> -- >> 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/d/optout. >> > > > > -- > R. Mark Volkmann > Object Computing, Inc. > > -- > 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/d/optout. > -- 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/d/optout.
