我希望仅在输入中设置时才需要添加输入.
<input-block
name="formName"
label="my label"
placeholder="test"
required
></input-block>
零件:
@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>
`
})
解决方法:
尝试类似的东西
<input type="text"
#myInput
name="{{name}}"
placeholder="{{placeholder}}"
[attr.required]="myInput.value ? "required" : null">