0

I have a custom component in Angular:

@Component({
selector: 'spring-input',
template: `
  <div class="group">
    <input class="spring-input" type="text" [(ngModel)]="value" (blur)="onBlur()">
  </div>
  `
})

export class SpringInputControl implements ControlValueAccessor{
   @Input() isrequired: boolean;

How can I setup the isrequired @Input for this component so that someone can set the input element's required attribute like this?

<spring-input name="testcomponent" [(ngModel)]="testcomponent" [isrequired]="true"></spring-input>

The HTML5 input element required attribute bugs out when I try setting it using curly braces {{required}}

Andy
  • 23
  • 2
  • What error are you getting? You can set the required via attribute binding, see [this answer](http://stackoverflow.com/questions/36745734/how-to-add-conditional-attribute-in-angular-2) and [this](https://angular.io/docs/ts/latest/guide/template-syntax.html#other-bindings) section of the documentation. – Garth Mason Mar 14 '17 at 06:20
  • Thanks, but I figured it out. If I setup my component like this: @Input() isrequired: boolean = false; and [required]="isrequired". I can set the required property by – Andy Mar 14 '17 at 19:48

0 Answers0