How to create custom input component with ngModel working in angular 6?

前端 未结 5 1322
天命终不由人
天命终不由人 2020-12-12 21:00

Since I use inputs with a lot of the same directives and .css classes applyed, I want to extract the repeated code to some component like this:

  @Component(         


        
5条回答
  •  醉酒成梦
    2020-12-12 21:37

    You can use @Input directive for passing the externalValue into the component and binding with it.

    Here's a code:

      @Component({
      selector: "app-input",
      template: `
        
    `, }) export class InputComponent implements OnInit { @Input('externalValue') externalValue : any; }

    And in your parent component, you can use it like:

    
    

提交回复
热议问题