ng2 继承自组件并扩展父模板
ng2 inherit from component and extend parent template
我有一个组件继承自基础组件。
我想在派生组件中扩展基础组件的模板。
例如。
基本组件中的模板:
<div>
<button>1</button>
</div>
派生组件中的模板:
<div>
<button>2</button>
</div>
我想看看按钮 1 和按钮 2
有什么办法吗?
谢谢!
在 html 中,取决于按钮 2 的位置,只需使用模板 2 中的选择器,如下所示:
ts 按钮 2:
@Component({
selector: 'app-mybutton2',
html 按钮 1:
<div>
<button>1</button>
</div>
<app-mybutton2></app-mybutton2>
您不能扩展 html 个文件。但是,如果我很了解你,你需要创建自定义组件并在你的组件中使用它。
对于 typescript 文件,您可以使组件扩展任何 typescript class 并且两个 typescript 文件可以共享相同的模板 html 文件。
我有一个组件继承自基础组件。
我想在派生组件中扩展基础组件的模板。
例如。 基本组件中的模板:
<div>
<button>1</button>
</div>
派生组件中的模板:
<div>
<button>2</button>
</div>
我想看看按钮 1 和按钮 2
有什么办法吗? 谢谢!
在 html 中,取决于按钮 2 的位置,只需使用模板 2 中的选择器,如下所示:
ts 按钮 2:
@Component({
selector: 'app-mybutton2',
html 按钮 1:
<div>
<button>1</button>
</div>
<app-mybutton2></app-mybutton2>
您不能扩展 html 个文件。但是,如果我很了解你,你需要创建自定义组件并在你的组件中使用它。
对于 typescript 文件,您可以使组件扩展任何 typescript class 并且两个 typescript 文件可以共享相同的模板 html 文件。