enter image description hereenter image description here如何强制我的组件在客户端执行,比如nextjs中的"use client"?
这是我第一次在Angular使用ssr的体验,如果它被禁用,一切正常
enter image description hereenter image description here如何强制我的组件在客户端执行,比如nextjs中的"use client"?
这是我第一次在Angular使用ssr的体验,如果它被禁用,一切正常
在app.component.HTML中,我们可以用下面的布尔值将按钮包装在@if
或*ngFor
中.
import { isPlatformBrowser } from '@angular/common';
import { Component, OnInit, Inject, PLATFORM_ID } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.HTML',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
public isBrowser = isPlatformBrowser(this.platformId);
constructor(@Inject(PLATFORM_ID) private platformId: any) { }
}
HTML
@if(isBrowser) {
<auth-btn/>
}
/* we can use ngFor also! */
/* <ng-container *ngFor="isBrowser">
<auth-btn/>
</ng-container> */