Angular 2 - add attribute in template based on input value

angular, javascript

Solution

try something like that

<input type="text" 
        #myInput
        name="{{name}}"
        placeholder="{{placeholder}}"
        [attr.required]="myInput.value ? "required" : null">

Problem

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> ` }) ```

Original source