Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditionally add attribute in angular

Tags:

angularjs

I want to use the $scope to set if an attribute should be used or not in angular. Here is my scope:

fields:
    [
        {
            label: 'First Name',
            name: 'firstname',
            key: 'entry.326845034',
            type: 'text',
            required: true
        }
    ]

it's the required attribute I want to set. I'm imagining something like {{if fields.required == true | required}}, but I can''t find any documentation on it.

like image 239
Himmators Avatar asked Sep 12 '13 12:09

Himmators


1 Answers

Are you wanting to set required on a form element like this?

<input required>

If so you can use

<input ng-required="fields.required"> 

and the true/false state of the variable will end up applying or removing the required attribute on the input.

like image 67
John Munsch Avatar answered Sep 29 '22 10:09

John Munsch