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

1

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

What should i put in the template? I only know of ng-if, but that will affect the entire tag.
What do you want to achieve exactly in your template ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.