在Angular中,有一种方法可以在模块热重新加载后保留应用程序状态吗?与VueJS中发生的情况类似:
到目前为止,我已经让HMR在几个教程之后工作了,但它所做的只是重新加载应用程序而不进行实际的页面刷新.快满了,是的.但仍然不是它可能的地方.
有没有人得到这个实际工作?
PS:它与https://github.com/beeman/tutorial-angular-cli-hmr/issues/4有关
我正在尝试创建一个通用服务,它将获取一些远程数据并使用它创建一些对象.
@Injectable()
export class tService<T> {
private _data: BehaviorSubject<T[]> = new BehaviorSubject([]);
private url = '...url...'; // URL to web api
constructor(private http: HttpClient) {
this.http.get<T[]>(this.url).subscribe(theThings => {
theThings = _.map(theThings, (theThing) => new T(theThing));
this._data.next(theThings);
});
}
}
Run Code Online (Sandbox Code Playgroud)
这给了我错误T only refers to type, but is being used as a value here
.好没关系.我明白发生了什么.我已经看到了几个问类似问题的问题.
例如:
似乎我在某个时候遇到过类中硬编码的任何解决方案,或者在某个地方添加了T的类构造函数.但我无法弄清楚该怎么做.我的问题是被实例化的类在构造函数中有参数,我使用的是Angular的DI系统,所以我不能(???)将parmeter添加到服务的构造函数中.
constructor(private playersService: gService<Player>, private alliesService: gService<Ally>) { }
Run Code Online (Sandbox Code Playgroud)
任何人都可以知道我应该在这做什么?另外,如果可能的话,我更愿意回答不是某种"黑客".如果可以选择做一些几乎无法读取的东西,只需复制和粘贴服务几次并更改它所引用的类,我将采用第二种方法.