我想创建一个自定义库。应该导入自定义指令的地方!!一切都很好!自定义指令未实现
@Directive({
selector:'[demo-dir]',
})
export class DemoDirective{
constructor(private elref:ElementRef,private Renderer:Renderer2){
}
@HostListener('click') mouseover()
{
alert("test")
console.log("test")
}
ngOnInit()
{
this.Renderer.setStyle(this.elref.nativeElement,'color','red');
}
自定义库模块:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DemoComponent } from './demo.component';
import { DemoDirective } from './demo.directive';
@NgModule({
declarations: [DemoComponent,DemoDirective],
imports: [
CommonModule
],
exports:[DemoComponent]
})
export class DemoModule { }
并且我已经将我的自定义库模块导入了app.module.ts
答案 0 :(得分:0)
您编写的指令很好,您没有从CF
模块中导出DemoDirective
指令:
DemoModule
不导出指令,即使导入@NgModule({
declarations: [DemoComponent, DemoDirective],
imports: [
CommonModule
],
exports:[DemoComponent, DemoDirective]
})
export class DemoModule { }
,它也不会在其他组件中可见。