简体   繁体   English

从 Angular Material 组件扩展

[英]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.

相关问题 角形材料组件 - Material components for angular with routing 从另一个ExtJS自定义框架扩展组件 - Extending components from another ExtJS custom framework 通过自定义Angular Material模块导入组件 - Importing components through a custom Angular Material module 用茉莉花测试材料设计角组件 - Testing Material Design Angular components with jasmine Ng-Sweet-Alert-2中的角材料成分 - Angular Material Components in Ng-Sweet-Alert-2 使用指令将禁用设置为 angular 材料组件 - Setting disabled to angular material components using directive 创建一个组件,它是两个组件的“混合”(从2个组件扩展) - Creating a component that is the “mix” of two components (extending from 2 components) 从出现在所有组件上方的侧边栏 Material UI 创建组件 - Create components from sidebar Material UI that appear above all components ExtJS4-从单个基类扩展不同的组件 - ExtJS4 - Extending different components from a single base class @angular-material-components/datetime-picker - '@angular/material/datepicker"' 没有导出成员 'DateRange' - @angular-material-components/datetime-picker - '@angular/material/datepicker"' has no exported member 'DateRange'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM