Home > Blockchain >  The OnInit lifecycle hook is not found in my created angular component file
The OnInit lifecycle hook is not found in my created angular component file

Time:12-20

When I create a new component file in my angular project by " ng g c 'component name' ", OnInit is not there initially in my component file.

CodePudding user response:

It has been removed in Angular 15 by default. Just add it back yourself.

CodePudding user response:

It has been removed in Angular 15. You can also add it manually

@Component({
 ...
})
export class MyComponent extends OnInit {
  ngOnInit(): void {
    // your init code
  }
}

CodePudding user response:

you can add it manually by yourself

@Component({
 selector: 'app-component',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent extends OnInit {

  ngOnInit(): void { 
  }

}
  • Related