我想将指令应用于所有DIV元素子代的锚标记。如何限制指令的影响只应用子元素。
答案 0 :(得分:0)
您可以利用feature modules。可以在DIV
组件旁边的功能模块中声明锚定指令。
简而言之,该策略是:
anchor
指令,但不要导出DIV
组件。 anchor
指令将应用于DIV
组件内的所有锚点AppModule
功能模块的声明看起来像
import { CommonModule } from '@angular/common';
@NgModule({
imports: [CommonModule],
declarations: [TheDivComponent, AnchorDierctive],
exports: [TheDivComponent]
})
export class TheDivModule {}