Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I got json (model property) like this:

[
{type:'a', val:'something'},
{type:'b', val:'something'}
]

Based on value of 'type', i need to render different html markup. I know i can accomplish it via ng-repeat and ng-if.

But wondering, if there is a better way of doing it, something like templating or such so code will be refractored and maintainable in long run?

share|improve this question
    
this looks like a nice candidate for a directive –  przno Apr 23 '14 at 18:54
    
Thanks, it really looks cool and i can build upon provided example. In the meantime, i learned about ngInclude and ngView as well. To me, it looks like, any of three can serve my purpose. Which one is best approach according to you, and why(if you can explain)? –  user3133397 Apr 23 '14 at 19:28
    
exactly what you wrote: code will be refractored and maintainable in long run - with directives you create reusable code/components and they can be tested. With angular, sooner or later you will come to directives, I'm sure. –  przno Apr 24 '14 at 8:01
    
Great! then sticking with directives... thanks. –  user3133397 Apr 24 '14 at 9:27

1 Answer 1

up vote 0 down vote accepted

During the research, I came across few alternatives which are listed below.

  1. ngView
  2. ngInclude
  3. Angular Directives

For my requirement, I am sticking with directives instead.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.