0

I want to make a opacity effect when the page-component is loaded, but I found that it must be set a setTimeout() in order to operate successfully. Is there a better way?

For example:

component:

@Component({
  selector : 'my-app',
  template: `
  <div id="component" [ngClass]="{show: block}">
    content
  </div>
  `
})
export class FaderComponent implements OnInit {
  block: boolean = false
  constructor(){}
  ngOnInit() {

    setTimeout(()=>{
      this.block = true;
    },100)

  }
}

scss:

#component {
  opacity: 0;
  transition: 0.4s;
  &.show{
    opacity: 1;
  }
}
Arun Mohan
  • 1,207
  • 1
  • 5
  • 11
Finn
  • 1,323
  • 5
  • 24
  • 46
  • This framework has an animation module: https://angular.io/guide/animations read this Guide. – Anarno May 12 '20 at 05:24

1 Answers1

0

You can use example for reference to add animation on component load.