Skip to content

feat(@schematics/angular): remove ngOnInit from component template #24008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component, OnInit<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';<% if(standalone) {%>
import { <% if(changeDetection !== 'Default') { %>ChangeDetectionStrategy, <% }%>Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%> } from '@angular/core';<% if(standalone) {%>
import { CommonModule } from '@angular/common';<% } %>

@Component({<% if(!skipSelector) {%>
Expand All @@ -22,11 +22,6 @@ import { CommonModule } from '@angular/common';<% } %>
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
})
export class <%= classify(name) %><%= classify(type) %> implements OnInit {

constructor() { }

ngOnInit(): void {
}
export class <%= classify(name) %><%= classify(type) %> {

}
4 changes: 2 additions & 2 deletions packages/schematics/angular/component/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('Component Schematic', () => {
const tree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise();
const content = tree.readContent('/projects/bar/src/app/foo/foo.route.ts');
const testContent = tree.readContent('/projects/bar/src/app/foo/foo.route.spec.ts');
expect(content).toContain('export class FooRoute implements OnInit');
expect(content).toContain('export class FooRoute');
expect(testContent).toContain("describe('FooRoute'");
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.route.css');
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.route.html');
Expand All @@ -308,7 +308,7 @@ describe('Component Schematic', () => {
const tree = await schematicRunner.runSchematicAsync('component', options, appTree).toPromise();
const content = tree.readContent('/projects/bar/src/app/foo/foo.ts');
const testContent = tree.readContent('/projects/bar/src/app/foo/foo.spec.ts');
expect(content).toContain('export class Foo implements OnInit');
expect(content).toContain('export class Foo');
expect(testContent).toContain("describe('Foo'");
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.css');
expect(tree.files).toContain('/projects/bar/src/app/foo/foo.html');
Expand Down