import { Injectable } from '@angular/core';
@Injectable()
export class SpinnerService {
private _selector = '#spinner';
show() {
console.log(this._selector); // #spinner
$(this._selector).show();
}
hide() {
console.log(this._selector); // undefined
$(this._selector).hide();
}
}
第一次调用的是show函数,第二次调用的是hide函数。这个服务只提供到了根模块的providers中,是在惰性加载模块的组件中调用的函数
惰性加载的模块有自己的子注入器,注入的服务会创造一个新的实例。