angular ssr下使用document和window,location

2020-06-16 10:14:43 浏览数 (1)

angular ssr访问浏览器api.

  • document export class ExampleComponent { constructor(@Inject(DOCUMENT) document: any) { console.dir(document) } }
  • window const WINDOW = new InjectionToken<any>('window', { providedIn: 'root', factory: () => window }); export class ExampleComponent { constructor(@Inject(WINDOW) window: any) { console.dir(window) } }
  • location见官方例子;

0 人点赞