Reputation: 747
I want add required
to input only if it was set in input.
<input-block
name="formName"
label="my label"
placeholder="test"
required
></input-block>
Component:
@Component({
selector: 'input-block',
inputs: ['name', 'label', 'placeholder', 'required'],
template: `
<label class="input-block">
<span class="name">{{label}}</span>
<input type="text"
name="{{name}}"
placeholder="{{placeholder}}"
<!-- no idea: {{required ? 'required : ''}} -->
>
</label>
`
})
Upvotes: 4
Views: 2533
Reputation: 4920
try something like that
<input type="text"
#myInput
name="{{name}}"
placeholder="{{placeholder}}"
[attr.required]="myInput.value ? "required" : null">
Upvotes: 5