如何将html模板添加到指令中?这是一个不起作用的示例代码:
来自'@ angular / core'的import ; @Directive({selector:'[master-side-bar]',templateUrl:'master-side-bar.html'})导出类MasterSideBar {constructor(){console.log('Hello MasterSideBar Directive');
}}
我收到以下错误:
类型'{selector:string; templateUrl:string; }'不能赋值给'Directive'类型的参数 . 对象文字只能指定已知属性,'templateUrl'在类型'Directive'中不存在 .
2 回答
从您的代码中,您需要使用 component not指令 .
Component是唯一接受模板为HTML的指令 .
请检查Types of directives
希望能帮助到你!!
根据Angular文档,有两种类型的指令:属性和结构 . 他们都不支持模板 . 只需使用角度组件 . 您是否有必要使用指令?