Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

angular - 如何创建具有相同属性\方法的组件(How to create components with the same propertiesmethods)

Not even sure it is feasible in angular: I would like to create components which all have few same properties and methods, some kind of inheritance.

(甚至不能确定它在角度上是否可行:我想创建所有具有几乎相同的属性和方法,某种继承的组件。)

The components should be based on some kind of a component "template".

(组件应基于某种类型的组件“模板”。)

I don't want to include in each new components the set of shared properties and methods, I just want to refer them in the HTML or in a component ref instance, wheres they will be defined in the "template"\"parent" - where the components inherit from.

(我不想在每个新组件中包括一组共享的属性和方法,我只想在HTML或组件ref实例中引用它们,而它们将在“模板” \“父”中定义-组件从哪里继承。)
Is it feasible ?

(可行吗?)

  ask by Guy E translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In angular2+ is possible to inherit proprieties and methods from parent componet in this way:

(在angular2 +中,可以通过以下方式从父组件继承属性和方法:)

export class yourComponent extends yourBaseComponent .

(export class yourComponent extends yourBaseComponent 。)

You can use all proprieties and methods of yourBaseComponent in yourComponent through this, as they are properties and method of yourComponent and so it is possibile to use it in HTML template of yourComponent too.

(您可以通过它在yourComponent中使用yourBaseComponent的所有属性和方法,因为它们是yourComponent的属性和方法,因此也可以在yourComponent的HTML模板中使用它。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...