Javascript 角度-将组件类转发给子级

Javascript 角度-将组件类转发给子级,javascript,angular,Javascript,Angular,我在表单中使用自定义输入 自定义输入.component.html 我希望应用于自定义输入的类可以应用于我的内部输入(自定义输入末尾不能有任何类) 这是一个好的模式吗?如果是这样,我如何实现它?这可以通过使用@Input属性来接收类,使用[ngClass]来应用它,并使用ElementRef从父级清除它来实现 @Component({ selector: 'custom-input', templateUrl: './custom-input.component.html' })

我在表单中使用自定义输入


自定义输入.component.html


我希望应用于
自定义输入
的类可以应用于我的
内部输入
自定义输入
末尾不能有任何类)


这是一个好的模式吗?如果是这样,我如何实现它?

这可以通过使用
@Input
属性来接收类,使用
[ngClass]
来应用它,并使用
ElementRef
从父级清除它来实现

@Component({
  selector: 'custom-input',
  templateUrl: './custom-input.component.html'
})
export class CustomInputComponent implements OnInit {
  @Input('class') inputClass: string;

  constructor(private element: ElementRef<HTMLElement>) { }

  ngOnInit() {
    this.element.nativeElement.className = '';
  }
}
@组件({
选择器:“自定义输入”,
templateUrl:“./custom input.component.html”
})
导出类CustomInputComponent实现OnInit{
@Input('class')inputClass:字符串;
构造函数(私有元素:ElementRef){}
恩戈尼尼特(){
this.element.nativeElement.className='';
}
}




它不适用于动态类:
<input type="text" [ngClass]="inputClass">
<custom-input class="a-class b-class"></custom-input>