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见官方例子;