我在 Angular-6 service.ts 中使用私有(private)变量。
private tagSubject = new Subject<any>();
它被用作
sendNewTagMessage(message: string) {
this.tagSubject.next({ text: message });
}
clearNewTagMessage() {
this.tagSubject.next();
}
我想为 tagSubject 写一个单元测试。
我做不到
service.tagSubject.subscribe
在 规范 因为它给出了像 Property 'tagSubject' is private and only accessible within class
这样的错误.我现在能做什么。请帮忙。
最佳答案
component['tagSubject']
或者(component as any).tagSubject
关于angular - 访问spec.ts,Angular6中的私有(private)变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55336796/