如何将 html 模板添加到指令中?这是一个不起作用的示例代码:
import { Directive } from '@angular/core';
@Directive({
selector: '[master-side-bar]',
templateUrl : 'master-side-bar.html' })export class MasterSideBar {
constructor() {
console.log('Hello MasterSideBar Directive');
}
}
我收到以下错误:
Argument of type '{ selector: string; templateUrl: string; }' is not assignable to parameter of type 'Directive'. Object literal may only specify known properties, and 'templateUrl' does not exist in type 'Directive'.
最佳答案
从您的代码中,您需要使用 组件 不是指令。
组件是唯一接受模板为 HTML 的指令。
请查收 Types of directives
希望能帮助到你!!
关于angular2-directives - 如何在 Angular 2 指令中使用 templateUrl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44219553/