Skip to content

Commit a832c20

Browse files
Broccoangular-robot[bot]
authored andcommitted
feat(@schematics/angular): Implement a standalone flag for new applications
1 parent 6b6d92b commit a832c20

24 files changed

+463
-86
lines changed

packages/schematics/angular/application/files/src/index.html.template renamed to packages/schematics/angular/application/files/common-files/src/index.html.template

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
<link rel="icon" type="image/x-icon" href="favicon.ico">
99
</head>
1010
<body>
11-
<<%= prefix %>-root></<%= prefix %>-root>
11+
<<%= selector %>></<%= selector %>>
1212
</body>
1313
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { AppComponent } from './app.component';
3+
4+
describe('AppComponent', () => {
5+
beforeEach(async () => {
6+
await TestBed.configureTestingModule({
7+
imports: [AppComponent],
8+
}).compileComponents();
9+
});
10+
11+
it('should create the app', () => {
12+
const fixture = TestBed.createComponent(AppComponent);
13+
const app = fixture.componentInstance;
14+
expect(app).toBeTruthy();
15+
});
16+
17+
it(`should have the '<%= name %>' title`, () => {
18+
const fixture = TestBed.createComponent(AppComponent);
19+
const app = fixture.componentInstance;
20+
expect(app.title).toEqual('<%= name %>');
21+
});
22+
23+
it('should render title', () => {
24+
const fixture = TestBed.createComponent(AppComponent);
25+
fixture.detectChanges();
26+
const compiled = fixture.nativeElement as HTMLElement;
27+
expect(compiled.querySelector('.content span')?.textContent).toContain('<%= name %> app is running!');
28+
});
29+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component } from '@angular/core';
2+
import { CommonModule } from '@angular/common';<% if(routing) { %>
3+
import { RouterOutlet } from '@angular/router';<% } %>
4+
5+
@Component({
6+
selector: '<%= selector %>',
7+
standalone: true,<% if(inlineTemplate) { %>
8+
template: `
9+
<!--The content below is only a placeholder and can be replaced.-->
10+
<div style="text-align:center" class="content">
11+
<h1>
12+
Welcome to {{title}}!
13+
</h1>
14+
<span style="display: block">{{ title }} app is running!</span>
15+
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
16+
</div>
17+
<h2>Here are some links to help you start: </h2>
18+
<ul>
19+
<li>
20+
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
21+
</li>
22+
<li>
23+
<h2><a target="_blank" rel="noopener" href="https://angular.io/cli">CLI Documentation</a></h2>
24+
</li>
25+
<li>
26+
<h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">Angular blog</a></h2>
27+
</li>
28+
</ul>
29+
<% if (routing) {
30+
%><router-outlet></router-outlet><%
31+
} %>
32+
`,<% } else { %>
33+
templateUrl: './app.component.html',<% } if(inlineStyle) { %>
34+
styles: [],<% } else { %>
35+
styleUrls: ['./app.component.<%= style %>'], <% } %>
36+
imports: [CommonModule<% if(routing) { %>, RouterOutlet<% } %>]
37+
})
38+
export class AppComponent {
39+
title = '<%= name %>';
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { ApplicationConfig } from '@angular/core';<% if (routing) { %>
2+
import { provideRouter } from '@angular/router';
3+
4+
import { routes } from './app.routes';<% } %>
5+
6+
export const appConfig: ApplicationConfig = {
7+
providers: [<% if (routing) { %>provideRouter(routes) <% } %>],
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { Routes } from '@angular/router';
2+
3+
export const routes: Routes = [];
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { bootstrapApplication } from '@angular/platform-browser';
2+
import { appConfig } from './app/app.config';
3+
import { AppComponent } from './app/app.component';
4+
5+
bootstrapApplication(AppComponent, appConfig)
6+
.catch((err) => console.error(err));

0 commit comments

Comments
 (0)