Himmators
Himmators

Reputation: 15006

Add attribute without value

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 />

Upvotes: 3

Views: 1026

Answers (1)

LoremIpsum
LoremIpsum

Reputation: 4428

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

Upvotes: 1

Related Questions