【发布时间】:2022-01-24 19:16:05
【问题描述】:
【问题讨论】:
标签: javascript angular npm server-side-rendering angular-universal
【问题讨论】:
标签: javascript angular npm server-side-rendering angular-universal
import { isBrowser } from 'angular2-universal';
or
// app.browser
@NgModule({
providers: [
{ provide: 'isBrowser', useValue: true }
]
})
then inject from constructor
export class SomeComponent implements OnInit {
constructor(@Inject('isBrowser') private isBrowser: boolean)
ngOnInit() {
// example usage, this could be anywhere in this Component of course
if (this.isBrowser) {
alert('we're in the browser!');
}
}
<ng-container *ngIf="isBrowser">
<!-- mqttws31-component -->
<mqttws31-component></mqttws31-component>
</ng-container>
【讨论】: