它们在不同的地方(声明和提供者)声明.我知道该服务将@Injectable()注入到使用该服务的组件的构造函数中.但为什么必须这样呢?为什么我们不能在一个地方宣布?一个人可以做什么功能,另一个不能?
ngOnInit() {
console.log('this1: ', this);
this.dbService.chats$.on('value', function(snapshot) {
console.log('this2: ', this);
});
}
Run Code Online (Sandbox Code Playgroud)
第一个 console.log 包含 Component 的所有字段,而第二个控制台日志为null