0

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.

Andrew Allen
  • 6,512
  • 5
  • 30
  • 73

3 Answers3

3

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

@Component({
 ...
})
export class MyComponent extends OnInit {
  ngOnInit(): void {
    // your init code
  }
}
Andrew Allen
  • 6,512
  • 5
  • 30
  • 73
1

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

MGX
  • 2,534
  • 2
  • 14
1

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 { 
  }

}