[英]Extending from Angular Material Components
In my angular project I want to extend/inherit from angular material components instead of using material component itself(eg not mat-checkbox but just a regular checkbox which extends mat-checkbox).在我的 angular 项目中,我想从 angular material 组件中扩展/继承,而不是使用 material 组件本身(例如不是 mat-checkbox 而只是一个扩展 mat-checkbox 的常规复选框)。 In this way i want to inherit all properties and methods from mat checkbox.通过这种方式,我想从 mat 复选框继承所有属性和方法。 Unfortunately I'm facing with a compilation error.不幸的是,我面临编译错误。 Bellow you can find the link for stackblitz where you can take a look on the project and the error itself波纹管您可以找到 stackblitz 的链接,您可以在其中查看项目和错误本身
https://stackblitz.com/edit/angular-material-hulqfu?file=app%2Fcheckbox%2Fcheckbox.component.ts https://stackblitz.com/edit/angular-material-hulqfu?file=app%2Fcheckbox%2Fcheckbox.component.ts
Please take a look at the error in the console.请看一下控制台中的错误。
In order to be able to inherit from any Material component you need to first, as obvious it may seem, install and add the library to the project: https://material.angular.io/guide/getting-started
.为了能够继承任何 Material 组件,您首先需要安装库并将其添加到项目中: https://material.angular.io/guide/getting-started
: https://material.angular.io/guide/getting-started
。
Afterwards, I would recommend you to verify whether everything has been set correctly by trying to use the MatCheckbox in the AppComponent (or any already declared component).之后,我建议您尝试使用 AppComponent(或任何已声明的组件)中的 MatCheckbox 来验证是否所有设置都正确。 Remember to previously add the MatCheckboxModule to the AppModule (or its corresponding module) in the imports section.请记住之前将 MatCheckboxModule 添加到导入部分中的 AppModule(或其相应模块)。
Once you don't have any kind of errors, then you can create a component which extends from the respective Material component.一旦您没有任何类型的错误,您就可以创建一个从相应 Material 组件扩展的组件。 Don't forget to import it in the declarations section.不要忘记在声明部分导入它。
That should work since it is just Typescript inheritance, although I'm not sure what is exactly what you're looking to accomplish and whether inheritance is the best way to approach it.这应该可行,因为它只是 Typescript 继承,尽管我不确定您想要完成的究竟是什么,以及继承是否是处理它的最佳方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.