1

enter image description hereenter image description here How to force my component to be executed on client side, something like "use client" in nextjs?

It's my first experience with ssr in Angular, if it's disabled everything works fine

1
  • Don't post screenshots of code please Commented Apr 2, 2024 at 6:05

1 Answer 1

1

In your app.component.html, we can wrap the button inside an @if or *ngFor with the below boolean.

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> */
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.