我在Angular7应用程序中使用一个共享模块来使用
指令
在不同的其他模块中。
import { Directive, OnInit, HostBinding, Input } from '@angular/core';
@Directive({
selector: '[appServerSuccess]'
})
export class ServerSuccessDirective implements OnInit {
@Input() appServerSuccess: string;
@HostBinding()
get innerText() {
return this.appServerSuccess;
}
@HostBinding('class.success')
get success () {
return this.appServerSuccess.toLocaleLowerCase().includes('success');
}
constructor() {}
ngOnInit() {}
}
在
共享.module.ts
,我确实有一个
宣言
和
出口
指令:
import { NgModule } from "@angular/core";
import { ServerSuccessDirective } from './directives/server-success.directive';
@NgModule({
imports: [ ],
declarations: [ ServerSuccessDirective ],
exports: [ ServerSuccessDirective ]
})
export class SharedModule {}
在每个
应用模块.ts
在
用户.module.ts
,我确实有
共享模块
该指令正在应用程序中的不同组件中使用。
<div [appServerSuccess]="msg"></div>
这个
味精
通过服务传递为:
private messageSource = new BehaviorSubject('');
currentMessage = this.messageSource.asObservable();
constructor() {
changeMessage(msg: string) {
this.messageSource.next( msg );
}
}
在组件中
应用程序模块
,它工作正常,但在
用户模块
它引发以下错误:
无法读取未定义的属性“toLocaleLowerCase”
这意味着指令在
用户模块
.
这个
进口
在模块中,
宣言
和
出口
in SharedModule是正确的。我哪里做错了?
我一直在找,找到了这个
question
,看起来有点类似,但它没有解决我的问题。