3

I'm working on one of my first angular templates. While looping through an array, I would like to add the attribute required.

Every itteration of the array looks like this:

        {
            label: 'Last Name',
            name: 'lastname',
            key: 'entry.1417082936'
        }

I could simply add

            {
                label: 'Last Name',
                name: 'lastname',
                key: 'entry.1417082936',
                required: 'required', 
            }

and then add {{required}} to the template, but i'm wondering wether there is a cleaner way of doing it. I will need to add the pattern-attribute as well.

If the requierd: true is set I want the attribute requierd to be included into the html, to something like this:

<input required />

user3723637
  • 130
  • 8
Himmators
  • 14,278
  • 36
  • 132
  • 223
  • You may find this useful : http://stackoverflow.com/questions/15696416/what-is-the-best-way-to-conditionally-apply-attributes-in-angular – LoremIpsum Sep 12 '13 at 14:58

1 Answers1

1

Why don't you use a Boolean ? This is typically a good case for that !

LoremIpsum
  • 4,328
  • 1
  • 15
  • 17