Angular Universal Reload twice
Angular Universal App reload the content twice for the initial code, how to prevent this?
I have put my initial code in ngOnInit() still getting the same result.
Angular Universal first prerenders the js of your project in server side and then once the dom is rendered it switches to the client side, irrespective of the data fetched. Make sure you don't call the data or APIs again once you get it. This should help to stop the second reload.
例如,如果您只想在服务器端而不是在前端运行查询或代码(又称“不是两次”),则可以检查平台以查看代码的执行位置
import {Injectable, PLATFORM_ID} from '@angular/core';
import {isPlatformServer} from '@angular/common';
@Injectable()
export class Something {
constructor(@Inject(PLATFORM_ID) private platformId: Object) {
}
getSomething() {
if (isPlatformServer(this.platformId)) {
// Here we execute the code on the server side only
} else if (isPlatformServer(this.platformId)) {
// Here we execute the code on the browser side only
}
}
}
链接地址: http://www.djcxy.com/p/31302.html
上一篇: 角度通用:闪烁和风格