_id
stringlengths 21
254
| text
stringlengths 1
93.7k
| metadata
dict |
---|---|---|
angular/adev/src/content/examples/animations/src/app/about.component.ts_0_215 | import {Component} from '@angular/core';
@Component({
standalone: true,
selector: 'app-about',
templateUrl: './about.component.html',
styleUrls: ['./about.component.css'],
})
export class AboutComponent {}
| {
"end_byte": 215,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/about.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.1.ts_0_1299 | import {Component, Input} from '@angular/core';
import {
trigger,
transition,
state,
animate,
style,
keyframes,
AnimationEvent,
} from '@angular/animations';
@Component({
standalone: true,
selector: 'app-open-close',
animations: [
// #docregion trigger
trigger('openClose', [
state(
'open',
style({
height: '200px',
opacity: 1,
backgroundColor: 'yellow',
}),
),
state(
'close',
style({
height: '100px',
opacity: 0.5,
backgroundColor: 'green',
}),
),
// ...
transition('* => *', [
animate(
'1s',
keyframes([
style({opacity: 0.1, offset: 0.1}),
style({opacity: 0.6, offset: 0.2}),
style({opacity: 1, offset: 0.5}),
style({opacity: 0.2, offset: 0.7}),
]),
),
]),
]),
// #enddocregion trigger
],
templateUrl: 'open-close.component.html',
styleUrls: ['open-close.component.css'],
})
export class OpenCloseKeyframeComponent {
isOpen = false;
toggle() {
this.isOpen = !this.isOpen;
}
@Input() logging = false;
onAnimationEvent(event: AnimationEvent) {
if (!this.logging) {
return;
}
}
}
| {
"end_byte": 1299,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.1.ts"
} |
angular/adev/src/content/examples/animations/src/app/app.config.ts_0_480 | import {ApplicationConfig} from '@angular/core';
import {routes} from './app.routes';
import {provideRouter} from '@angular/router';
import {provideProtractorTestingSupport} from '@angular/platform-browser';
import {provideAnimations} from '@angular/platform-browser/animations';
export const appConfig: ApplicationConfig = {
providers: [
// needed for supporting e2e tests
provideProtractorTestingSupport(),
provideRouter(routes),
provideAnimations(),
],
};
| {
"end_byte": 480,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/app.config.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-enter-leave.component.ts_0_1251 | import {Component, Input, Output, EventEmitter} from '@angular/core';
import {trigger, state, style, animate, transition} from '@angular/animations';
import {Hero} from './hero';
import {NgFor} from '@angular/common';
@Component({
standalone: true,
selector: 'app-hero-list-enter-leave',
template: `
<ul class="heroes">
@for (hero of heroes; track hero) {
<li [@flyInOut]="'in'">
<button class="inner" type="button" (click)="removeHero(hero.id)">
<span class="badge">{{ hero.id }}</span>
<span class="name">{{ hero.name }}</span>
</button>
</li>
}
</ul>
`,
styleUrls: ['./hero-list-page.component.css'],
imports: [NgFor],
// #docregion animationdef
animations: [
trigger('flyInOut', [
state('in', style({transform: 'translateX(0)'})),
transition('void => *', [style({transform: 'translateX(-100%)'}), animate(100)]),
transition('* => void', [animate(100, style({transform: 'translateX(100%)'}))]),
]),
],
// #enddocregion animationdef
})
export class HeroListEnterLeaveComponent {
@Input() heroes: Hero[] = [];
@Output() remove = new EventEmitter<number>();
removeHero(id: number) {
this.remove.emit(id);
}
}
| {
"end_byte": 1251,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-enter-leave.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/home.component.html_0_45 | <p>
Welcome to Animations in Angular!
</p>
| {
"end_byte": 45,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/home.component.html"
} |
angular/adev/src/content/examples/animations/src/app/status-slider.component.css_0_178 | :host {
display: block;
}
.box {
width: 300px;
border: 5px solid black;
display: block;
line-height: 300px;
text-align: center;
font-size: 50px;
color: white;
}
| {
"end_byte": 178,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/status-slider.component.css"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.ts_0_2986 | // #docplaster
import {Component, Input} from '@angular/core';
import {trigger, transition, state, animate, style, AnimationEvent} from '@angular/animations';
// #docregion component, events1
@Component({
standalone: true,
selector: 'app-open-close',
// #docregion trigger-wildcard1, trigger-transition
animations: [
trigger('openClose', [
// #docregion state1
// ...
// #enddocregion events1
state(
'open',
style({
height: '200px',
opacity: 1,
backgroundColor: 'yellow',
}),
),
// #enddocregion state1
// #docregion state2
state(
'closed',
style({
height: '100px',
opacity: 0.8,
backgroundColor: 'blue',
}),
),
// #enddocregion state2, trigger-wildcard1
// #docregion transition1
transition('open => closed', [animate('1s')]),
// #enddocregion transition1
// #docregion transition2
transition('closed => open', [animate('0.5s')]),
// #enddocregion transition2, component
// #docregion trigger-wildcard1
transition('* => closed', [animate('1s')]),
transition('* => open', [animate('0.5s')]),
// #enddocregion trigger-wildcard1
// #docregion trigger-wildcard2
transition('open <=> closed', [animate('0.5s')]),
// #enddocregion trigger-wildcard2
// #docregion transition4
transition('* => open', [animate('1s', style({opacity: '*'}))]),
// #enddocregion transition4
transition('* => *', [animate('1s')]),
// #enddocregion trigger-transition
// #docregion component, trigger-wildcard1, events1
]),
],
// #enddocregion trigger-wildcard1
templateUrl: 'open-close.component.html',
styleUrls: ['open-close.component.css'],
})
// #docregion events
export class OpenCloseComponent {
// #enddocregion events1, events, component
@Input() logging = false;
// #docregion component
isOpen = true;
toggle() {
this.isOpen = !this.isOpen;
}
// #enddocregion component
// #docregion events1, events
onAnimationEvent(event: AnimationEvent) {
// #enddocregion events1, events
if (!this.logging) {
return;
}
// #docregion events
// openClose is trigger name in this example
console.warn(`Animation Trigger: ${event.triggerName}`);
// phaseName is "start" or "done"
console.warn(`Phase: ${event.phaseName}`);
// in our example, totalTime is 1000 (number of milliseconds in a second)
console.warn(`Total time: ${event.totalTime}`);
// in our example, fromState is either "open" or "closed"
console.warn(`From: ${event.fromState}`);
// in our example, toState either "open" or "closed"
console.warn(`To: ${event.toState}`);
// the HTML element itself, the button in this case
console.warn(`Element: ${event.element}`);
// #docregion events1
}
// #docregion component
}
// #enddocregion component
| {
"end_byte": 2986,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.html_0_308 | <button type="button" (click)="toggle()">Toggle Open/Close</button>
<div [@openClose]="isOpen ? 'open' : 'closed'"
(@openClose.start)="onAnimationEvent($event)"
(@openClose.done)="onAnimationEvent($event)"
class="open-close-container">
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
</div>
| {
"end_byte": 308,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.html"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.4.ts_0_1214 | // #docplaster
// #docregion
import {Component} from '@angular/core';
import {trigger, transition, state, animate, style} from '@angular/animations';
// #docregion toggle-animation
@Component({
// #enddocregion toggle-animation
standalone: true,
selector: 'app-open-close-toggle',
templateUrl: 'open-close.component.4.html',
styleUrls: ['open-close.component.css'],
// #docregion toggle-animation
animations: [
trigger('childAnimation', [
// ...
// #enddocregion toggle-animation
state(
'open',
style({
width: '250px',
opacity: 1,
backgroundColor: 'yellow',
}),
),
state(
'closed',
style({
width: '100px',
opacity: 0.8,
backgroundColor: 'blue',
}),
),
transition('* => *', [animate('1s')]),
// #docregion toggle-animation
]),
],
})
export class OpenCloseChildComponent {
isDisabled = false;
isOpen = false;
// #enddocregion toggle-animation
toggleAnimations() {
this.isDisabled = !this.isDisabled;
}
toggle() {
this.isOpen = !this.isOpen;
}
// #docregion toggle-animation
}
// #enddocregion toggle-animation
| {
"end_byte": 1214,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.4.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-enter-leave-page.component.ts_0_637 | import {Component} from '@angular/core';
import {HEROES} from './mock-heroes';
import {HeroListEnterLeaveComponent} from './hero-list-enter-leave.component';
@Component({
standalone: true,
selector: 'app-hero-list-enter-leave-page',
template: `
<section>
<h2>Enter/Leave</h2>
<app-hero-list-enter-leave [heroes]="heroes" (remove)="onRemove($event)"></app-hero-list-enter-leave>
</section>
`,
imports: [HeroListEnterLeaveComponent],
})
export class HeroListEnterLeavePageComponent {
heroes = HEROES.slice();
onRemove(id: number) {
this.heroes = this.heroes.filter((hero) => hero.id !== id);
}
}
| {
"end_byte": 637,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-enter-leave-page.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/insert-remove.component.ts_0_765 | // #docplaster
import {Component} from '@angular/core';
import {trigger, transition, animate, style} from '@angular/animations';
import {NgIf} from '@angular/common';
@Component({
standalone: true,
selector: 'app-insert-remove',
imports: [NgIf],
animations: [
// #docregion enter-leave-trigger
trigger('myInsertRemoveTrigger', [
transition(':enter', [style({opacity: 0}), animate('100ms', style({opacity: 1}))]),
transition(':leave', [animate('100ms', style({opacity: 0}))]),
]),
// #enddocregion enter-leave-trigger
],
templateUrl: 'insert-remove.component.html',
styleUrls: ['insert-remove.component.css'],
})
export class InsertRemoveComponent {
isShown = false;
toggle() {
this.isShown = !this.isShown;
}
}
| {
"end_byte": 765,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/insert-remove.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/app.component.css_0_126 | nav a {
padding: .7rem;
}
h1 {
margin-bottom: .3rem;
}
form {
margin-bottom: 2rem;
}
nav {
padding-bottom: 3rem;
}
| {
"end_byte": 126,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/app.component.css"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-auto.component.html_0_301 | <ul class="heroes">
@for (hero of heroes; track hero) {
<li
[@shrinkOut]="'in'">
<button class="inner" type="button" (click)="removeHero(hero.id)">
<span class="badge">{{ hero.id }}</span>
<span class="name">{{ hero.name }}</span>
</button>
</li>
}
</ul>
| {
"end_byte": 301,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-auto.component.html"
} |
angular/adev/src/content/examples/animations/src/app/app.module.1.ts_0_307 | import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
@NgModule({
imports: [BrowserModule, BrowserAnimationsModule],
declarations: [],
bootstrap: [],
})
export class AppModule {}
| {
"end_byte": 307,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/app.module.1.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.1.html_0_306 | <!-- #docplaster -->
<!-- #docregion trigger -->
<nav>
<button type="button" (click)="toggle()">Toggle Open/Close</button>
</nav>
<div [@openClose]="isOpen ? 'open' : 'closed'" class="open-close-container">
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
</div>
<!-- #enddocregion trigger -->
| {
"end_byte": 306,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.1.html"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-group-page.component.ts_0_608 | import {Component} from '@angular/core';
import {HEROES} from './mock-heroes';
import {HeroListGroupsComponent} from './hero-list-groups.component';
@Component({
standalone: true,
selector: 'app-hero-list-groups-page',
template: `
<section>
<h2>Hero List Group</h2>
<app-hero-list-groups [heroes]="heroes" (remove)="onRemove($event)"></app-hero-list-groups>
</section>
`,
imports: [HeroListGroupsComponent],
})
export class HeroListGroupPageComponent {
heroes = HEROES.slice();
onRemove(id: number) {
this.heroes = this.heroes.filter((hero) => hero.id !== id);
}
}
| {
"end_byte": 608,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-group-page.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close-page.component.ts_0_632 | import {Component} from '@angular/core';
import {OpenCloseComponent} from './open-close.component';
@Component({
standalone: true,
selector: 'app-open-close-page',
template: `
<section>
<h2>Open Close Component</h2>
<input type="checkbox" id="log-checkbox" [checked]="logging" (click)="toggleLogging()"/>
<label for="log-checkbox">Console Log Animation Events</label>
<app-open-close [logging]="logging"></app-open-close>
</section>
`,
imports: [OpenCloseComponent],
})
export class OpenClosePageComponent {
logging = false;
toggleLogging() {
this.logging = !this.logging;
}
}
| {
"end_byte": 632,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close-page.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/insert-remove.component.css_0_195 | :host {
display: block;
}
.insert-remove-container {
border: 1px solid #dddddd;
margin-top: 1em;
padding: 20px 20px 0px 20px;
color: #000000;
font-weight: bold;
font-size: 20px;
}
| {
"end_byte": 195,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/insert-remove.component.css"
} |
angular/adev/src/content/examples/animations/src/app/animations.1.ts_0_741 | // #docplaster
// #docregion animation-const, trigger-const
import {animation, style, animate, trigger, transition, useAnimation} from '@angular/animations';
// #enddocregion trigger-const
export const transitionAnimation = animation([
style({
height: '{{ height }}',
opacity: '{{ opacity }}',
backgroundColor: '{{ backgroundColor }}',
}),
animate('{{ time }}'),
]);
// #enddocregion animation-const
// #docregion trigger-const
export const triggerAnimation = trigger('openClose', [
transition('open => closed', [
useAnimation(transitionAnimation, {
params: {
height: 0,
opacity: 1,
backgroundColor: 'red',
time: '1s',
},
}),
]),
]);
// #enddocregion trigger-const
| {
"end_byte": 741,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/animations.1.ts"
} |
angular/adev/src/content/examples/animations/src/app/animations.ts_0_1914 | import {
animation,
trigger,
animateChild,
group,
transition,
animate,
style,
query,
} from '@angular/animations';
export const transitionAnimation = animation([
style({
height: '{{ height }}',
opacity: '{{ opacity }}',
backgroundColor: '{{ backgroundColor }}',
}),
animate('{{ time }}'),
]);
// Routable animations
// #docregion route-animations
export const slideInAnimation =
// #docregion style-view
trigger('routeAnimations', [
transition('HomePage <=> AboutPage', [
style({position: 'relative'}),
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
}),
]),
// #enddocregion style-view
// #docregion query
query(':enter', [style({left: '-100%'})], {optional: true}),
query(':leave', animateChild(), {optional: true}),
group([
query(':leave', [animate('300ms ease-out', style({left: '100%'}))], {optional: true}),
query(':enter', [animate('300ms ease-out', style({left: '0%'}))], {optional: true}),
]),
]),
transition('* <=> *', [
style({position: 'relative'}),
query(
':enter, :leave',
[
style({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
}),
],
{optional: true},
),
query(':enter', [style({left: '-100%'})], {optional: true}),
query(':leave', animateChild(), {optional: true}),
group([
query(':leave', [animate('200ms ease-out', style({left: '100%', opacity: 0}))], {
optional: true,
}),
query(':enter', [animate('300ms ease-out', style({left: '0%'}))], {optional: true}),
query('@*', animateChild(), {optional: true}),
]),
]),
// #enddocregion query
]);
// #enddocregion route-animations
| {
"end_byte": 1914,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/animations.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-page.component.ts_0_2368 | // #docplaster
// #docregion
import {Component, HostBinding, OnInit} from '@angular/core';
import {trigger, transition, animate, style, query, stagger} from '@angular/animations';
import {HEROES} from './mock-heroes';
import {Hero} from './hero';
import {NgFor} from '@angular/common';
// #docregion filter-animations
@Component({
// #enddocregion filter-animations
standalone: true,
imports: [NgFor],
selector: 'app-hero-list-page',
templateUrl: 'hero-list-page.component.html',
styleUrls: ['hero-list-page.component.css'],
// #docregion page-animations, filter-animations
animations: [
// #enddocregion filter-animations
trigger('pageAnimations', [
transition(':enter', [
query('.hero', [
style({opacity: 0, transform: 'translateY(-100px)'}),
stagger(30, [
animate('500ms cubic-bezier(0.35, 0, 0.25, 1)', style({opacity: 1, transform: 'none'})),
]),
]),
]),
]),
// #enddocregion page-animations
// #docregion increment
// #docregion filter-animations
trigger('filterAnimation', [
transition(':enter, * => 0, * => -1', []),
transition(':increment', [
query(
':enter',
[
style({opacity: 0, width: 0}),
stagger(50, [animate('300ms ease-out', style({opacity: 1, width: '*'}))]),
],
{optional: true},
),
]),
transition(':decrement', [
query(':leave', [stagger(50, [animate('300ms ease-out', style({opacity: 0, width: 0}))])]),
]),
]),
// #enddocregion increment
],
})
export class HeroListPageComponent implements OnInit {
// #enddocregion filter-animations
@HostBinding('@pageAnimations')
public animatePage = true;
// #docregion filter-animations
heroesTotal = -1;
get heroes() {
return this._heroes;
}
private _heroes: Hero[] = [];
ngOnInit() {
this._heroes = HEROES;
}
updateCriteria(criteria: string) {
criteria = criteria ? criteria.trim() : '';
this._heroes = HEROES.filter((hero) =>
hero.name.toLowerCase().includes(criteria.toLowerCase()),
);
const newTotal = this.heroes.length;
if (this.heroesTotal !== newTotal) {
this.heroesTotal = newTotal;
} else if (!criteria) {
this.heroesTotal = -1;
}
}
}
// #enddocregion filter-animations
| {
"end_byte": 2368,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-page.component.ts"
} |
angular/adev/src/content/examples/reactive-forms/BUILD.bazel_0_545 | package(default_visibility = ["//visibility:public"])
exports_files([
"src/app/app.component.1.html",
"src/app/app.module.ts",
"src/app/name-editor/name-editor.component.html",
"src/app/name-editor/name-editor.component.ts",
"src/app/profile-editor/profile-editor.component.1.html",
"src/app/profile-editor/profile-editor.component.1.ts",
"src/app/profile-editor/profile-editor.component.2.ts",
"src/app/profile-editor/profile-editor.component.html",
"src/app/profile-editor/profile-editor.component.ts",
])
| {
"end_byte": 545,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/BUILD.bazel"
} |
angular/adev/src/content/examples/reactive-forms/e2e/src/app.e2e-spec.ts_0_4802 | import {browser, element, by} from 'protractor';
describe('Reactive forms', () => {
const nameEditor = element(by.css('app-name-editor'));
const profileEditor = element(by.css('app-profile-editor'));
const nameEditorButton = element(by.cssContainingText('app-root > nav > button', 'Name Editor'));
const profileEditorButton = element(
by.cssContainingText('app-root > nav > button', 'Profile Editor'),
);
beforeAll(() => browser.get(''));
describe('Name Editor', () => {
const nameInput = nameEditor.element(by.css('input'));
const updateButton = nameEditor.element(by.buttonText('Update Name'));
const nameText = 'John Smith';
beforeAll(async () => {
await nameEditorButton.click();
});
beforeEach(async () => {
await nameInput.clear();
});
it('should update the name value when the name control is updated', async () => {
await nameInput.sendKeys(nameText);
const value = await nameInput.getAttribute('value');
expect(value).toBe(nameText);
});
it('should update the name control when the Update Name button is clicked', async () => {
await nameInput.sendKeys(nameText);
const value1 = await nameInput.getAttribute('value');
expect(value1).toBe(nameText);
await updateButton.click();
const value2 = await nameInput.getAttribute('value');
expect(value2).toBe('Nancy');
});
it('should update the displayed control value when the name control updated', async () => {
await nameInput.sendKeys(nameText);
const valueElement = nameEditor.element(by.cssContainingText('p', 'Value:'));
const nameValueElement = await valueElement.getText();
const nameValue = nameValueElement.toString().replace('Value: ', '');
expect(nameValue).toBe(nameText);
});
});
describe('Profile Editor', () => {
const firstNameInput = getInput('firstName');
const streetInput = getInput('street');
const addAliasButton = element(by.buttonText('+ Add another alias'));
const updateButton = profileEditor.element(by.buttonText('Update Profile'));
const profile: Record<string, string | number> = {
firstName: 'John',
lastName: 'Smith',
street: '345 South Lane',
city: 'Northtown',
state: 'XX',
zip: 12345,
};
beforeAll(async () => {
await profileEditorButton.click();
});
beforeEach(async () => {
await browser.get('');
await profileEditorButton.click();
});
it('should be invalid by default', async () => {
expect(await profileEditor.getText()).toContain('Form Status: INVALID');
});
it('should be valid if the First Name is filled in', async () => {
await firstNameInput.clear();
await firstNameInput.sendKeys('John Smith');
expect(await profileEditor.getText()).toContain('Form Status: VALID');
});
it('should update the name when the button is clicked', async () => {
await firstNameInput.clear();
await streetInput.clear();
await firstNameInput.sendKeys('John');
await streetInput.sendKeys('345 Smith Lane');
const firstNameInitial = await firstNameInput.getAttribute('value');
const streetNameInitial = await streetInput.getAttribute('value');
expect(firstNameInitial).toBe('John');
expect(streetNameInitial).toBe('345 Smith Lane');
await updateButton.click();
const nameValue = await firstNameInput.getAttribute('value');
const streetValue = await streetInput.getAttribute('value');
expect(nameValue).toBe('Nancy');
expect(streetValue).toBe('123 Drew Street');
});
it('should add an alias field when the Add Alias button is clicked', async () => {
await addAliasButton.click();
const aliasInputs = profileEditor.all(by.cssContainingText('label', 'Alias'));
expect(await aliasInputs.count()).toBe(2);
});
it('should update the displayed form value when form inputs are updated', async () => {
const aliasText = 'Johnny';
await Promise.all(
Object.keys(profile).map((key) => getInput(key).sendKeys(`${profile[key]}`)),
);
const aliasInput = profileEditor.all(by.css('#alias-0'));
await aliasInput.sendKeys(aliasText);
const formValueElement = profileEditor.all(by.cssContainingText('p', 'Form Value:'));
const formValue = await formValueElement.getText();
const formJson = JSON.parse(formValue.toString().replace('Form Value:', ''));
expect(profile['firstName']).toBe(formJson.firstName);
expect(profile['lastName']).toBe(formJson.lastName);
expect(formJson.aliases[0]).toBe(aliasText);
});
});
function getInput(key: string) {
return element(by.css(`input[formcontrolname=${key}`));
}
});
| {
"end_byte": 4802,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/index.html_0_269 | <!DOCTYPE html>
<!-- #docregion -->
<html lang="en">
<head>
<title>Angular Reactive Forms</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
| {
"end_byte": 269,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/index.html"
} |
angular/adev/src/content/examples/reactive-forms/src/main.ts_0_214 | import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
| {
"end_byte": 214,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/main.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/app.component.html_0_325 | <h1>Reactive Forms</h1>
<nav>
<button type="button" (click)="toggleEditor('name')">Name Editor</button>
<button type="button" (click)="toggleEditor('profile')">Profile Editor</button>
</nav>
<app-name-editor *ngIf="showNameEditor"></app-name-editor>
<app-profile-editor *ngIf="showProfileEditor"></app-profile-editor>
| {
"end_byte": 325,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/app.component.html"
} |
angular/adev/src/content/examples/reactive-forms/src/app/app.module.ts_0_869 | // #docplaster
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
// #docregion imports
import {ReactiveFormsModule} from '@angular/forms';
// #enddocregion imports
import {AppComponent} from './app.component';
import {NameEditorComponent} from './name-editor/name-editor.component';
import {ProfileEditorComponent} from './profile-editor/profile-editor.component';
// #docregion imports
@NgModule({
// #enddocregion imports
declarations: [AppComponent, NameEditorComponent, ProfileEditorComponent],
// #docregion imports
imports: [
// #enddocregion imports
BrowserModule,
// #docregion imports
// other imports ...
ReactiveFormsModule,
],
// #enddocregion imports
providers: [],
bootstrap: [AppComponent],
// #docregion imports
})
export class AppModule {}
// #enddocregion imports
| {
"end_byte": 869,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/app.module.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/app.component.ts_0_487 | import {Component} from '@angular/core';
export type EditorType = 'name' | 'profile';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
standalone: false,
})
export class AppComponent {
editor: EditorType = 'name';
get showNameEditor() {
return this.editor === 'name';
}
get showProfileEditor() {
return this.editor === 'profile';
}
toggleEditor(type: EditorType) {
this.editor = type;
}
}
| {
"end_byte": 487,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/app.component.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/app.component.css_0_54 | nav button {
padding: 1rem;
font-size: inherit;
}
| {
"end_byte": 54,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/app.component.css"
} |
angular/adev/src/content/examples/reactive-forms/src/app/app.component.1.html_0_278 | <!-- #docplaster -->
<h1>Reactive Forms</h1>
<!-- #docregion app-name-editor-->
<app-name-editor></app-name-editor>
<!-- #enddocregion app-name-editor-->
<!-- #docregion app-profile-editor -->
<app-profile-editor></app-profile-editor>
<!-- #enddocregion app-profile-editor --> | {
"end_byte": 278,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/app.component.1.html"
} |
angular/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.1.ts_0_1133 | // #docplaster
// #docregion formgroup, nested-formgroup
import {Component} from '@angular/core';
// #docregion imports
import {FormGroup, FormControl} from '@angular/forms';
// #enddocregion imports
@Component({
selector: 'app-profile-editor',
templateUrl: './profile-editor.component.html',
styleUrls: ['./profile-editor.component.css'],
standalone: false,
})
export class ProfileEditorComponent {
// #docregion formgroup-compare
profileForm = new FormGroup({
firstName: new FormControl(''),
lastName: new FormControl(''),
// #enddocregion formgroup
address: new FormGroup({
street: new FormControl(''),
city: new FormControl(''),
state: new FormControl(''),
zip: new FormControl(''),
}),
// #docregion formgroup
});
// #enddocregion formgroup, nested-formgroup, formgroup-compare
// #docregion patch-value
updateProfile() {
this.profileForm.patchValue({
firstName: 'Nancy',
address: {
street: '123 Drew Street',
},
});
}
// #enddocregion patch-value
// #docregion formgroup, nested-formgroup
}
// #enddocregion formgroup
| {
"end_byte": 1133,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.1.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.html_0_1725 | <!-- #docplaster -->
<!-- #docregion ng-submit -->
<form [formGroup]="profileForm" (ngSubmit)="onSubmit()">
<!-- #enddocregion ng-submit -->
<label for="first-name">First Name: </label>
<input id="first-name" type="text" formControlName="firstName" required>
<label for="last-name">Last Name: </label>
<input id="last-name" type="text" formControlName="lastName">
<div formGroupName="address">
<h2>Address</h2>
<label for="street">Street: </label>
<input id="street" type="text" formControlName="street">
<label for="city">City: </label>
<input id="city" type="text" formControlName="city">
<label for="state">State: </label>
<input id="state" type="text" formControlName="state">
<label for="zip">Zip Code: </label>
<input id="zip"type="text" formControlName="zip">
</div>
<!-- #docregion formarrayname -->
<div formArrayName="aliases">
<h2>Aliases</h2>
<button type="button" (click)="addAlias()">+ Add another alias</button>
<div *ngFor="let alias of aliases.controls; let i=index">
<!-- The repeated alias template -->
<label for="alias-{{ i }}">Alias:</label>
<input id="alias-{{ i }}" type="text" [formControlName]="i">
</div>
</div>
<!-- #enddocregion formarrayname -->
<!-- #docregion submit-button -->
<p>Complete the form to enable button.</p>
<button type="submit" [disabled]="!profileForm.valid">Submit</button>
<!-- #enddocregion submit-button -->
</form>
<hr>
<p>Form Value: {{ profileForm.value | json }}</p>
<!-- #docregion display-status -->
<p>Form Status: {{ profileForm.status }}</p>
<!-- #enddocregion display-status -->
<button type="button" (click)="updateProfile()">Update Profile</button>
| {
"end_byte": 1725,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.html"
} |
angular/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.1.html_0_1508 | <!-- #docplaster -->
<!-- #docregion formgroup -->
<form [formGroup]="profileForm">
<label for="first-name">First Name: </label>
<input id="first-name" type="text" formControlName="firstName">
<label for="last-name">Last Name: </label>
<input id="last-name" type="text" formControlName="lastName">
<!-- #enddocregion formgroup -->
<!-- #docregion formgroupname -->
<div formGroupName="address">
<h2>Address</h2>
<label for="street">Street: </label>
<input id="street" type="text" formControlName="street">
<label for="city">City: </label>
<input id="city" type="text" formControlName="city">
<label for="state">State: </label>
<input id="state" type="text" formControlName="state">
<label for="zip">Zip Code: </label>
<input id="zip" type="text" formControlName="zip">
</div>
<!-- #enddocregion formgroupname -->
<div formArrayName="aliases">
<h2>Aliases</h2>
<button type="button" (click)="addAlias()">+ Add another alias</button>
<div *ngFor="let address of aliases.controls; let i=index">
<!-- The repeated alias template -->
<label for="alias-{{ i }}">Alias: </label>
<input id="alias-{{ i }}" type="text" [formControlName]="i">
</div>
</div>
<!-- #docregion formgroup -->
</form>
<!-- #enddocregion formgroup -->
<p>Form Value: {{ profileForm.value | json }}</p>
<!-- #docregion patch-value -->
<button type="button" (click)="updateProfile()">Update Profile</button>
<!-- #enddocregion patch-value -->
| {
"end_byte": 1508,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.1.html"
} |
angular/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.ts_0_1571 | // #docplaster
import {Component} from '@angular/core';
import {FormBuilder} from '@angular/forms';
// #docregion validator-imports
import {Validators} from '@angular/forms';
// #enddocregion validator-imports
import {FormArray} from '@angular/forms';
@Component({
selector: 'app-profile-editor',
templateUrl: './profile-editor.component.html',
styleUrls: ['./profile-editor.component.css'],
standalone: false,
})
export class ProfileEditorComponent {
// #docregion required-validator, aliases
profileForm = this.formBuilder.group({
firstName: ['', Validators.required],
lastName: [''],
address: this.formBuilder.group({
street: [''],
city: [''],
state: [''],
zip: [''],
}),
// #enddocregion required-validator
aliases: this.formBuilder.array([this.formBuilder.control('')]),
// #docregion required-validator
});
// #enddocregion required-validator, aliases
// #docregion aliases-getter
get aliases() {
return this.profileForm.get('aliases') as FormArray;
}
// #enddocregion aliases-getter
constructor(private formBuilder: FormBuilder) {}
updateProfile() {
this.profileForm.patchValue({
firstName: 'Nancy',
address: {
street: '123 Drew Street',
},
});
}
// #docregion add-alias
addAlias() {
this.aliases.push(this.formBuilder.control(''));
}
// #enddocregion add-alias
// #docregion on-submit
onSubmit() {
// TODO: Use EventEmitter with form value
console.warn(this.profileForm.value);
}
// #enddocregion on-submit
}
| {
"end_byte": 1571,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.2.ts_0_1565 | // #docplaster
// #docregion form-builder
import {Component, inject} from '@angular/core';
// #docregion form-builder-imports
import {FormBuilder} from '@angular/forms';
// #enddocregion form-builder-imports, form-builder
// #docregion form-array-imports
import {FormArray} from '@angular/forms';
// #docregion form-builder-imports, form-builder
// #enddocregion form-builder-imports, form-array-imports
@Component({
selector: 'app-profile-editor',
templateUrl: './profile-editor.component.html',
styleUrls: ['./profile-editor.component.css'],
standalone: false,
})
export class ProfileEditorComponent {
// #docregion inject-form-builder
private formBuilder = inject(FormBuilder);
// #enddocregion inject-form-builder
// #docregion formgroup-compare
profileForm = this.formBuilder.group({
firstName: [''],
lastName: [''],
address: this.formBuilder.group({
street: [''],
city: [''],
state: [''],
zip: [''],
}),
// #enddocregion form-builder, formgroup-compare
aliases: this.formBuilder.array([this.formBuilder.control('')]),
// #docregion form-builder, formgroup-compare
});
// #enddocregion form-builder, formgroup-compare
get aliases() {
return this.profileForm.get('aliases') as FormArray;
}
updateProfile() {
this.profileForm.patchValue({
firstName: 'Nancy',
address: {
street: '123 Drew Street',
},
});
}
addAlias() {
this.aliases.push(this.formBuilder.control(''));
}
// #docregion form-builder
}
// #enddocregion form-builder
| {
"end_byte": 1565,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.2.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.css_0_149 | /* ProfileEditorComponent's private CSS styles */
form {
padding-top: 1rem;
}
label {
display: block;
margin: .5em 0;
font-weight: bold;
}
| {
"end_byte": 149,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/profile-editor/profile-editor.component.css"
} |
angular/adev/src/content/examples/reactive-forms/src/app/name-editor/name-editor.component.ts_0_571 | // #docplaster
// #docregion create-control
import {Component} from '@angular/core';
import {FormControl} from '@angular/forms';
@Component({
selector: 'app-name-editor',
templateUrl: './name-editor.component.html',
styleUrls: ['./name-editor.component.css'],
standalone: false,
})
export class NameEditorComponent {
name = new FormControl('');
// #enddocregion create-control
// #docregion update-value
updateName() {
this.name.setValue('Nancy');
}
// #enddocregion update-value
// #docregion create-control
}
// #enddocregion create-control
| {
"end_byte": 571,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/name-editor/name-editor.component.ts"
} |
angular/adev/src/content/examples/reactive-forms/src/app/name-editor/name-editor.component.css_0_134 | label {
font-weight: bold;
padding-bottom: .5rem;
padding-top: 1rem;
display: inline-block;
}
button {
max-width: 300px;
}
| {
"end_byte": 134,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/name-editor/name-editor.component.css"
} |
angular/adev/src/content/examples/reactive-forms/src/app/name-editor/name-editor.component.html_0_398 | <!-- #docregion control-binding -->
<label for="name">Name: </label>
<input id="name" type="text" [formControl]="name">
<!-- #enddocregion control-binding -->
<!-- #docregion display-value -->
<p>Value: {{ name.value }}</p>
<!-- #enddocregion display-value -->
<!-- #docregion update-value -->
<button type="button" (click)="updateName()">Update Name</button>
<!-- #enddocregion update-value -->
| {
"end_byte": 398,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/reactive-forms/src/app/name-editor/name-editor.component.html"
} |
angular/adev/src/content/examples/dynamic-form/BUILD.bazel_0_473 | package(default_visibility = ["//visibility:public"])
exports_files([
"src/app/app.component.ts",
"src/app/dynamic-form.component.html",
"src/app/dynamic-form.component.ts",
"src/app/dynamic-form-question.component.html",
"src/app/dynamic-form-question.component.ts",
"src/app/question.service.ts",
"src/app/question-base.ts",
"src/app/question-control.service.ts",
"src/app/question-dropdown.ts",
"src/app/question-textbox.ts",
])
| {
"end_byte": 473,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/BUILD.bazel"
} |
angular/adev/src/content/examples/dynamic-form/e2e/src/app.e2e-spec.ts_0_802 | import {browser, element, by} from 'protractor';
describe('Dynamic Form', () => {
beforeAll(() => browser.get(''));
it('should submit form', async () => {
const firstNameElement = element.all(by.css('input[id=firstName]')).get(0);
expect(await firstNameElement.getAttribute('value')).toEqual('Bombasto');
const emailElement = element.all(by.css('input[id=emailAddress]')).get(0);
const email = '[email protected]';
await emailElement.sendKeys(email);
expect(await emailElement.getAttribute('value')).toEqual(email);
await element(by.css('select option[value="solid"]')).click();
await element.all(by.css('button')).get(0).click();
expect(
await element(by.cssContainingText('strong', 'Saved the following values')).isPresent(),
).toBe(true);
});
});
| {
"end_byte": 802,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/index.html_0_311 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<base href="/">
<title>Dynamic Form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/sample.css">
</head>
<body>
<app-root></app-root>
</body>
</html>
| {
"end_byte": 311,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/index.html"
} |
angular/adev/src/content/examples/dynamic-form/src/main.ts_0_254 | // #docregion
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [provideProtractorTestingSupport()],
});
| {
"end_byte": 254,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/main.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/question-control.service.ts_0_551 | // #docregion
import {Injectable} from '@angular/core';
import {FormControl, FormGroup, Validators} from '@angular/forms';
import {QuestionBase} from './question-base';
@Injectable()
export class QuestionControlService {
toFormGroup(questions: QuestionBase<string>[]) {
const group: any = {};
questions.forEach((question) => {
group[question.key] = question.required
? new FormControl(question.value || '', Validators.required)
: new FormControl(question.value || '');
});
return new FormGroup(group);
}
}
| {
"end_byte": 551,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/question-control.service.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/question-textbox.ts_0_159 | // #docregion
import {QuestionBase} from './question-base';
export class TextboxQuestion extends QuestionBase<string> {
override controlType = 'textbox';
}
| {
"end_byte": 159,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/question-textbox.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/question.service.ts_0_1088 | // #docregion
import {Injectable} from '@angular/core';
import {DropdownQuestion} from './question-dropdown';
import {QuestionBase} from './question-base';
import {TextboxQuestion} from './question-textbox';
import {of} from 'rxjs';
@Injectable()
export class QuestionService {
// TODO: get from a remote source of question metadata
getQuestions() {
const questions: QuestionBase<string>[] = [
new DropdownQuestion({
key: 'favoriteAnimal',
label: 'Favorite Animal',
options: [
{key: 'cat', value: 'Cat'},
{key: 'dog', value: 'Dog'},
{key: 'horse', value: 'Horse'},
{key: 'capybara', value: 'Capybara'},
],
order: 3,
}),
new TextboxQuestion({
key: 'firstName',
label: 'First name',
value: 'Alex',
required: true,
order: 1,
}),
new TextboxQuestion({
key: 'emailAddress',
label: 'Email',
type: 'email',
order: 2,
}),
];
return of(questions.sort((a, b) => a.order - b.order));
}
}
| {
"end_byte": 1088,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/question.service.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/app.component.ts_0_762 | // #docregion
import {Component} from '@angular/core';
import {AsyncPipe} from '@angular/common';
import {DynamicFormComponent} from './dynamic-form.component';
import {QuestionService} from './question.service';
import {QuestionBase} from './question-base';
import {Observable} from 'rxjs';
@Component({
standalone: true,
selector: 'app-root',
template: `
<div>
<h2>Job Application for Heroes</h2>
<app-dynamic-form [questions]="questions$ | async"></app-dynamic-form>
</div>
`,
providers: [QuestionService],
imports: [AsyncPipe, DynamicFormComponent],
})
export class AppComponent {
questions$: Observable<QuestionBase<any>[]>;
constructor(service: QuestionService) {
this.questions$ = service.getQuestions();
}
}
| {
"end_byte": 762,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/app.component.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/dynamic-form-question.component.html_0_628 | <!-- #docregion -->
<div [formGroup]="form">
<label [attr.for]="question.key">{{ question.label }}</label>
<div>
@switch (question.controlType) {
@case ('textbox') {
<input [formControlName]="question.key" [id]="question.key" [type]="question.type">
} @case ('dropdown') {
<select [id]="question.key" [formControlName]="question.key">
@for (opt of question.options; track opt) {
<option [value]="opt.key">{{ opt.value }}</option>
}
</select>
}
}
</div>
@if (!isValid) {<div class="errorMessage">{{ question.label }} is required</div>}
</div>
| {
"end_byte": 628,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/dynamic-form-question.component.html"
} |
angular/adev/src/content/examples/dynamic-form/src/app/question-base.ts_0_818 | // #docregion
export class QuestionBase<T> {
value: T | undefined;
key: string;
label: string;
required: boolean;
order: number;
controlType: string;
type: string;
options: {key: string; value: string}[];
constructor(
options: {
value?: T;
key?: string;
label?: string;
required?: boolean;
order?: number;
controlType?: string;
type?: string;
options?: {key: string; value: string}[];
} = {},
) {
this.value = options.value;
this.key = options.key || '';
this.label = options.label || '';
this.required = !!options.required;
this.order = options.order === undefined ? 1 : options.order;
this.controlType = options.controlType || '';
this.type = options.type || '';
this.options = options.options || [];
}
}
| {
"end_byte": 818,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/question-base.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/dynamic-form-question.component.ts_0_585 | // #docregion
import {Component, Input} from '@angular/core';
import {FormGroup, ReactiveFormsModule} from '@angular/forms';
import {CommonModule} from '@angular/common';
import {QuestionBase} from './question-base';
@Component({
standalone: true,
selector: 'app-question',
templateUrl: './dynamic-form-question.component.html',
imports: [CommonModule, ReactiveFormsModule],
})
export class DynamicFormQuestionComponent {
@Input() question!: QuestionBase<string>;
@Input() form!: FormGroup;
get isValid() {
return this.form.controls[this.question.key].valid;
}
}
| {
"end_byte": 585,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/dynamic-form-question.component.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.ts_0_993 | // #docregion
import {Component, Input, OnInit} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormGroup, ReactiveFormsModule} from '@angular/forms';
import {DynamicFormQuestionComponent} from './dynamic-form-question.component';
import {QuestionBase} from './question-base';
import {QuestionControlService} from './question-control.service';
@Component({
standalone: true,
selector: 'app-dynamic-form',
templateUrl: './dynamic-form.component.html',
providers: [QuestionControlService],
imports: [CommonModule, DynamicFormQuestionComponent, ReactiveFormsModule],
})
export class DynamicFormComponent implements OnInit {
@Input() questions: QuestionBase<string>[] | null = [];
form!: FormGroup;
payLoad = '';
constructor(private qcs: QuestionControlService) {}
ngOnInit() {
this.form = this.qcs.toFormGroup(this.questions as QuestionBase<string>[]);
}
onSubmit() {
this.payLoad = JSON.stringify(this.form.getRawValue());
}
}
| {
"end_byte": 993,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.html_0_503 | <!-- #docregion -->
<div>
<form (ngSubmit)="onSubmit()" [formGroup]="form">
@for (question of questions; track question) {
<div class="form-row">
<app-question [question]="question" [form]="form"></app-question>
</div>
}
<div class="form-row">
<button type="submit" [disabled]="!form.valid">Save</button>
</div>
</form>
@if (payLoad) {
<div class="form-row">
<strong>Saved the following values</strong><br>{{ payLoad }}
</div>
}
</div>
| {
"end_byte": 503,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/dynamic-form.component.html"
} |
angular/adev/src/content/examples/dynamic-form/src/app/question-dropdown.ts_0_161 | // #docregion
import {QuestionBase} from './question-base';
export class DropdownQuestion extends QuestionBase<string> {
override controlType = 'dropdown';
}
| {
"end_byte": 161,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/app/question-dropdown.ts"
} |
angular/adev/src/content/examples/dynamic-form/src/assets/sample.css_0_63 | .errorMessage{
color:red;
}
.form-row{
margin-top: 10px;
} | {
"end_byte": 63,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dynamic-form/src/assets/sample.css"
} |
angular/adev/src/content/examples/router/BUILD.bazel_0_132 | package(default_visibility = ["//visibility:public"])
exports_files([
"src/app/app.component.1.html",
"src/index.html",
])
| {
"end_byte": 132,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/BUILD.bazel"
} |
angular/adev/src/content/examples/router/e2e/src/app.e2e-spec.ts_0_7042 | import {browser, element, by, ExpectedConditions as EC} from 'protractor';
const numDashboardTabs = 5;
const numCrises = 4;
const numHeroes = 9;
describe('Router', () => {
beforeAll(() => browser.get(''));
function getPageStruct() {
const hrefEles = element.all(by.css('nav a'));
const crisisDetail = element
.all(by.css('app-crisis-center > app-crisis-list > app-crisis-detail > div'))
.first();
const heroDetail = element(by.css('app-hero-detail'));
return {
hrefs: hrefEles,
activeHref: element(by.css('nav a.active')),
crisisHref: hrefEles.get(0),
crisisList: element.all(by.css('app-crisis-center app-crisis-list li')),
crisisDetail,
crisisDetailTitle: crisisDetail.element(by.xpath('*[1]')),
heroesHref: hrefEles.get(1),
heroesList: element.all(by.css('app-hero-list li')),
heroDetail,
heroDetailTitle: heroDetail.element(by.xpath('*[2]')),
adminHref: hrefEles.get(2),
adminPage: element(by.css('app-admin')),
adminPreloadList: element.all(by.css('app-admin > app-admin-dashboard > ul > li')),
loginHref: hrefEles.get(3),
loginButton: element.all(by.css('app-login > p > button')),
contactHref: hrefEles.get(4),
contactCancelButton: element.all(by.buttonText('Cancel')),
primaryOutlet: element.all(by.css('app-hero-list')),
secondaryOutlet: element.all(by.css('app-compose-message')),
};
}
it('has expected dashboard tabs', async () => {
const page = getPageStruct();
expect(await page.hrefs.count()).toEqual(numDashboardTabs, 'dashboard tab count');
expect(await page.crisisHref.getText()).toEqual('Crisis Center');
expect(await page.heroesHref.getText()).toEqual('Heroes');
expect(await page.adminHref.getText()).toEqual('Admin');
expect(await page.loginHref.getText()).toEqual('Login');
expect(await page.contactHref.getText()).toEqual('Contact');
});
it('has heroes selected as opening tab', async () => {
const page = getPageStruct();
expect(await page.activeHref.getText()).toEqual('Heroes');
});
it('has crises center items', async () => {
const page = getPageStruct();
await page.crisisHref.click();
expect(await page.activeHref.getText()).toEqual('Crisis Center');
expect(await page.crisisList.count()).toBe(numCrises, 'crisis list count');
});
it('has hero items', async () => {
const page = getPageStruct();
await page.heroesHref.click();
expect(await page.activeHref.getText()).toEqual('Heroes');
expect(await page.heroesList.count()).toBe(numHeroes, 'hero list count');
});
it('toggles views', async () => {
const page = getPageStruct();
await page.crisisHref.click();
expect(await page.activeHref.getText()).toEqual('Crisis Center');
expect(await page.crisisList.count()).toBe(numCrises, 'crisis list count');
await page.heroesHref.click();
expect(await page.activeHref.getText()).toEqual('Heroes');
expect(await page.heroesList.count()).toBe(numHeroes, 'hero list count');
});
it('saves changed crisis details', async () => {
const page = getPageStruct();
await page.crisisHref.click();
await crisisCenterEdit(2, true);
});
// TODO: Figure out why this test is failing now
xit('can cancel changed crisis details', async () => {
const page = getPageStruct();
await page.crisisHref.click();
await crisisCenterEdit(3, false);
});
it('saves changed hero details', async () => {
const page = getPageStruct();
await page.heroesHref.click();
await browser.sleep(600);
const heroEle = page.heroesList.get(4);
const text = await heroEle.getText();
expect(text.length).toBeGreaterThan(0, 'hero item text length');
// remove leading id from text
const heroText = text.slice(text.indexOf(' ')).trim();
await heroEle.click();
await browser.sleep(600);
expect(await page.heroesList.count()).toBe(0, 'hero list count');
expect(await page.heroDetail.isPresent()).toBe(true, 'hero detail');
expect(await page.heroDetailTitle.getText()).toContain(heroText);
const inputEle = page.heroDetail.element(by.css('input'));
await inputEle.sendKeys('-foo');
expect(await page.heroDetailTitle.getText()).toContain(heroText + '-foo');
const buttonEle = page.heroDetail.element(by.css('button'));
await buttonEle.click();
await browser.sleep(600);
expect(await heroEle.getText()).toContain(heroText + '-foo');
});
it('sees preloaded modules', async () => {
const page = getPageStruct();
await page.loginHref.click();
await page.loginButton.click();
const list = page.adminPreloadList;
expect(await list.count()).toBe(1, 'preloaded module');
expect(await list.first().getText()).toBe('crisis-center', 'first preloaded module');
});
it('sees the secondary route', async () => {
const page = getPageStruct();
await page.heroesHref.click();
await page.contactHref.click();
expect(await page.primaryOutlet.count()).toBe(1, 'primary outlet');
expect(await page.secondaryOutlet.count()).toBe(1, 'secondary outlet');
});
it('should redirect with secondary route', async () => {
const page = getPageStruct();
// go to login page and login
await browser.get('');
await page.loginHref.click();
await page.loginButton.click();
// open secondary outlet
await page.contactHref.click();
// go to login page and logout
await page.loginHref.click();
await page.loginButton.click();
// attempt to go to admin page, redirects to login with secondary outlet open
await page.adminHref.click();
// login, get redirected back to admin with outlet still open
await page.loginButton.click();
expect(await page.adminPage.isDisplayed()).toBeTruthy();
expect(await page.secondaryOutlet.count()).toBeTruthy();
});
async function crisisCenterEdit(index: number, save: boolean) {
const page = getPageStruct();
await page.crisisHref.click();
let crisisEle = page.crisisList.get(index);
const text = await crisisEle.getText();
expect(text.length).toBeGreaterThan(0, 'crisis item text length');
// remove leading id from text
const crisisText = text.slice(text.indexOf(' ')).trim();
await crisisEle.click();
expect(await page.crisisDetail.isPresent()).toBe(true, 'crisis detail present');
expect(await page.crisisDetailTitle.getText()).toContain(crisisText);
const inputEle = page.crisisDetail.element(by.css('input'));
await inputEle.sendKeys('-foo');
const buttonEle = page.crisisDetail.element(by.buttonText(save ? 'Save' : 'Cancel'));
await buttonEle.click();
crisisEle = page.crisisList.get(index);
if (save) {
expect(await crisisEle.getText()).toContain(crisisText + '-foo');
} else {
await browser.wait(EC.alertIsPresent(), 4000);
await browser.switchTo().alert().accept();
expect(await crisisEle.getText()).toContain(crisisText);
}
}
});
| {
"end_byte": 7042,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/router/src/index.html_0_406 | <!DOCTYPE html>
<!-- #docregion -->
<html lang="en">
<head>
<!-- Set the base href -->
<!-- #docregion base-href -->
<base href="/">
<!-- #enddocregion base-href -->
<title>Angular Router</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
<!-- #enddocregion -->
| {
"end_byte": 406,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/index.html"
} |
angular/adev/src/content/examples/router/src/main.ts_0_228 | // #docregion
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
| {
"end_byte": 228,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/main.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.html_0_713 | <!-- #docregion -->
<div class="wrapper">
<h1 class="title">Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active" ariaCurrentWhenActive="page">Crisis Center</a>
<a routerLink="/superheroes" routerLinkActive="active" ariaCurrentWhenActive="page">Heroes</a>
<a routerLink="/admin" routerLinkActive="active" ariaCurrentWhenActive="page">Admin</a>
<a routerLink="/login" routerLinkActive="active" ariaCurrentWhenActive="page">Login</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
</nav>
<div [@routeAnimation]="getRouteAnimationData()">
<router-outlet></router-outlet>
</div>
<router-outlet name="popup"></router-outlet>
</div>
| {
"end_byte": 713,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.html"
} |
angular/adev/src/content/examples/router/src/app/message.service.ts_0_245 | import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class MessageService {
messages: string[] = [];
add(message: string) {
this.messages.push(message);
}
clear() {
this.messages = [];
}
}
| {
"end_byte": 245,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/message.service.ts"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.ts_0_1293 | // #docplaster
// #docregion
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {authGuard} from './auth/auth.guard';
import {SelectivePreloadingStrategyService} from './selective-preloading-strategy.service';
const appRoutes: Routes = [
{
path: 'compose',
component: ComposeMessageComponent,
outlet: 'popup',
},
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then((m) => m.AdminModule),
canMatch: [authGuard],
},
// #docregion preload-v2
{
path: 'crisis-center',
loadChildren: () =>
import('./crisis-center/crisis-center.module').then((m) => m.CrisisCenterModule),
data: {preload: true},
},
// #enddocregion preload-v2
{path: '', redirectTo: '/superheroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
RouterModule.forRoot(appRoutes, {
enableTracing: false, // <-- debugging purposes only
preloadingStrategy: SelectivePreloadingStrategyService,
}),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 1293,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.4.ts_0_348 | import {Component} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
standalone: false,
})
export class AppComponent {
// #docregion relative-to
goToItems() {
this.router.navigate(['items'], {relativeTo: this.route});
}
// #enddocregion relative-to
}
| {
"end_byte": 348,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.4.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.7.ts_0_1310 | // #docregion
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {Router} from '@angular/router';
import {AppComponent} from './app.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {AppRoutingModule} from './app-routing.module';
import {HeroesModule} from './heroes/heroes.module';
import {CrisisCenterModule} from './crisis-center/crisis-center.module';
import {AuthModule} from './auth/auth.module';
@NgModule({
imports: [
BrowserModule,
FormsModule,
HeroesModule,
CrisisCenterModule,
AuthModule,
AppRoutingModule,
],
declarations: [AppComponent, ComposeMessageComponent, PageNotFoundComponent],
bootstrap: [AppComponent],
})
// #docregion inspect-config
export class AppModule {
// Diagnostic only: inspect router configuration
constructor(router: Router) {
// Use a custom replacer to display function names in the route configs
const replacer = (key, value) => (typeof value === 'function' ? value.name : value);
console.log('Routes: ', JSON.stringify(router.config, replacer, 2));
}
}
// #enddocregion inspect-config
| {
"end_byte": 1310,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.7.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.2.html_0_340 | <!-- #docregion -->
<h1>Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active" ariaCurrentWhenActive="page">Crisis Center</a>
<a routerLink="/heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Heroes</a>
</nav>
<div [@routeAnimation]="getAnimationData()">
<router-outlet></router-outlet>
</div> | {
"end_byte": 340,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.2.html"
} |
angular/adev/src/content/examples/router/src/app/app.module.3.ts_0_1164 | // #docplaster
// #docregion
// #docregion remove-heroes
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
// #enddocregion remove-heroes
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
// #docregion remove-heroes
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {HeroesModule} from './heroes/heroes.module';
import {CrisisListComponent} from './crisis-list/crisis-list.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
@NgModule({
// #docregion module-imports
imports: [
BrowserModule,
// #enddocregion module-imports
// #enddocregion remove-heroes
BrowserAnimationsModule,
// #docregion remove-heroes
// #docregion module-imports
FormsModule,
HeroesModule,
AppRoutingModule,
],
// #enddocregion module-imports
declarations: [AppComponent, CrisisListComponent, PageNotFoundComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
// #enddocregion remove-heroes
// #enddocregion
| {
"end_byte": 1164,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.3.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.1.ts_0_219 | // #docregion
import {Component} from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
standalone: false,
})
export class AppComponent {}
| {
"end_byte": 219,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.1.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.2.ts_0_690 | import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {CrisisListComponent} from './crisis-list/crisis-list.component';
import {HeroListComponent} from './hero-list/hero-list.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
@NgModule({
imports: [BrowserModule, FormsModule, AppRoutingModule],
declarations: [AppComponent, HeroListComponent, CrisisListComponent, PageNotFoundComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
| {
"end_byte": 690,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.2.ts"
} |
angular/adev/src/content/examples/router/src/app/selective-preloading-strategy.service.ts_0_734 | // #docregion
import {Injectable} from '@angular/core';
import {PreloadingStrategy, Route} from '@angular/router';
import {Observable, of} from 'rxjs';
@Injectable({
providedIn: 'root',
})
export class SelectivePreloadingStrategyService implements PreloadingStrategy {
preloadedModules: string[] = [];
preload(route: Route, load: () => Observable<any>): Observable<any> {
if (route.canMatch === undefined && route.data?.['preload'] && route.path != null) {
// add the route path to the preloaded module array
this.preloadedModules.push(route.path);
// log the route path to the console
console.log('Preloaded: ' + route.path);
return load();
} else {
return of(null);
}
}
}
| {
"end_byte": 734,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/selective-preloading-strategy.service.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.6.ts_0_637 | // #docregion
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {Routes, RouterModule} from '@angular/router';
import {AppComponent} from './app.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
const routes: Routes = [];
@NgModule({
imports: [
BrowserModule,
FormsModule,
RouterModule.forRoot(routes, {useHash: true}), // .../#/crisis-center/
],
declarations: [AppComponent, PageNotFoundComponent],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
| {
"end_byte": 637,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.6.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.4.html_0_587 | <!-- #docregion -->
<h1>Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active" ariaCurrentWhenActive="page">Crisis Center</a>
<a routerLink="/heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Heroes</a>
<!-- #docregion contact-link -->
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
<!-- #enddocregion contact-link -->
</nav>
<!-- #docregion outlets -->
<div [@routeAnimation]="getAnimationData()">
<router-outlet></router-outlet>
</div>
<router-outlet name="popup"></router-outlet>
<!-- #enddocregion outlets --> | {
"end_byte": 587,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.4.html"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.10.ts_0_1568 | // #docplaster
import {Injectable, NgModule} from '@angular/core';
import {Title} from '@angular/platform-browser';
import {ResolveFn, RouterModule, RouterStateSnapshot, Routes, TitleStrategy} from '@angular/router'; // CLI imports router
// #docregion page-title
const routes: Routes = [
{
path: 'first-component',
title: 'First component',
component: FirstComponent, // this is the component with the <router-outlet> in the template
children: [
{
path: 'child-a', // child route path
title: resolvedChildATitle,
component: ChildAComponent, // child route component that the router renders
},
{
path: 'child-b',
title: 'child b',
component: ChildBComponent, // another child route component that the router renders
},
],
},
];
const resolvedChildATitle: ResolveFn<string> = () => Promise.resolve('child a');
// #enddocregion page-title
// #docregion custom-page-title
@Injectable({providedIn: 'root'})
export class TemplatePageTitleStrategy extends TitleStrategy {
constructor(private readonly title: Title) {
super();
}
override updateTitle(routerState: RouterStateSnapshot) {
const title = this.buildTitle(routerState);
if (title !== undefined) {
this.title.setTitle(`My Application | ${title}`);
}
}
}
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
providers: [{provide: TitleStrategy, useClass: TemplatePageTitleStrategy}],
})
export class AppRoutingModule {}
// #enddocregion custom-page-title
| {
"end_byte": 1568,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.10.ts"
} |
angular/adev/src/content/examples/router/src/app/dialog.service.ts_0_653 | // #docregion
import {Injectable} from '@angular/core';
import {Observable, of} from 'rxjs';
/**
* Async modal dialog service
* DialogService makes this app easier to test by faking this service.
* TODO: better modal implementation that doesn't use window.confirm
*/
@Injectable({
providedIn: 'root',
})
export class DialogService {
/**
* Ask user to confirm an action. `message` explains the action and choices.
* Returns observable resolving to `true`=confirm or `false`=cancel
*/
confirm(message?: string): Observable<boolean> {
const confirmation = window.confirm(message || 'Is it OK?');
return of(confirmation);
}
}
| {
"end_byte": 653,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/dialog.service.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.8.html_0_501 | <!-- #docregion child-routes-->
<h2>First Component</h2>
<nav>
<ul>
<li><a routerLink="child-a">Child A</a></li>
<li><a routerLink="child-b">Child B</a></li>
</ul>
</nav>
<router-outlet></router-outlet>
<!-- #enddocregion child-routes-->
<!-- #docregion relative-route-->
<h2>First Component</h2>
<nav>
<ul>
<li><a routerLink="../second-component">Relative Route to second component</a></li>
</ul>
</nav>
<router-outlet></router-outlet>
<!-- #enddocregion relative-route-->
| {
"end_byte": 501,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.8.html"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.4.ts_0_767 | // #docregion
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {CanDeactivateGuard} from './can-deactivate.guard';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
const appRoutes: Routes = [
{
path: 'compose',
component: ComposeMessageComponent,
outlet: 'popup',
},
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 767,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.4.ts"
} |
angular/adev/src/content/examples/router/src/app/can-deactivate.guard.ts_0_397 | // #docregion
import {CanDeactivateFn} from '@angular/router';
import {Observable} from 'rxjs';
export interface CanComponentDeactivate {
canDeactivate?: () => Observable<boolean> | Promise<boolean> | boolean;
}
export const canDeactivateGuard: CanDeactivateFn<CanComponentDeactivate> = (
component: CanComponentDeactivate,
) => (component.canDeactivate ? component.canDeactivate() : true);
| {
"end_byte": 397,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/can-deactivate.guard.ts"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.5.ts_0_1027 | // #docplaster
// #docregion
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {authGuard} from './auth/auth.guard';
const appRoutes: Routes = [
{
path: 'compose',
component: ComposeMessageComponent,
outlet: 'popup',
},
// #docregion admin, admin-1
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then((m) => m.AdminModule),
// #enddocregion admin-1
canMatch: [authGuard],
// #docregion admin-1
},
// #enddocregion admin, admin-1
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 1027,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.5.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.8.ts_0_471 | import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppRoutingModule} from './app-routing.module'; // CLI imports AppRoutingModule
import {AppComponent} from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
AppRoutingModule, // CLI adds AppRoutingModule to the AppModule's imports array
],
providers: [],
bootstrap: [AppComponent],
})
export class AppModule {}
| {
"end_byte": 471,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.8.ts"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.11.ts_0_1070 | import {NgModule} from '@angular/core';
import {provideRouter, Routes, withComponentInputBinding} from '@angular/router';
import {authGuard} from './auth/auth.guard';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
const appRoutes: Routes = [
{path: 'compose', component: ComposeMessageComponent, outlet: 'popup'},
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then((m) => m.AdminModule),
canMatch: [authGuard],
},
{
path: 'crisis-center',
loadChildren: () =>
import('./crisis-center/crisis-center.module').then((m) => m.CrisisCenterModule),
data: {preload: true},
},
{path: '', redirectTo: '/superheroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
// #docregion withComponentInputBinding
providers: [provideRouter(appRoutes, withComponentInputBinding())],
// #enddocregion withComponentInputBinding
})
export class AppRoutingModule {}
| {
"end_byte": 1070,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.11.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.ts_0_1768 | // #docplaster
// #docregion auth, preload
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
// #docregion animations-module
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
// #enddocregion auth, animations-module
import {Router} from '@angular/router';
// #docregion auth
import {AppComponent} from './app.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {AppRoutingModule} from './app-routing.module';
import {HeroesModule} from './heroes/heroes.module';
import {AuthModule} from './auth/auth.module';
// #docregion animations-module
@NgModule({
imports: [
// #enddocregion animations-module
BrowserModule,
// #docregion animations-module
BrowserAnimationsModule,
// #enddocregion animations-module
FormsModule,
HeroesModule,
AuthModule,
AppRoutingModule,
// #docregion animations-module
],
// #enddocregion animations-module
declarations: [AppComponent, ComposeMessageComponent, PageNotFoundComponent],
bootstrap: [AppComponent],
// #docregion animations-module
})
// #enddocregion animations-module
export class AppModule {
// #enddocregion preload, auth
// Diagnostic only: inspect router configuration
constructor(router: Router) {
// Use a custom replacer to display function names in the route configs
// const replacer = (key, value) => (typeof value === 'function') ? value.name : value;
// console.log('Routes: ', JSON.stringify(router.config, replacer, 2));
}
// #docregion preload, auth
}
// #enddocregion preload, auth
| {
"end_byte": 1768,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.5.html_0_559 | <!-- #docregion -->
<h1 class="title">Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active" ariaCurrentWhenActive="page">Crisis Center</a>
<a routerLink="/heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Heroes</a>
<a routerLink="/admin" routerLinkActive="active" ariaCurrentWhenActive="page">Admin</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
</nav>
<div [@routeAnimation]="getAnimationData()">
<router-outlet></router-outlet>
</div>
<router-outlet name="popup"></router-outlet> | {
"end_byte": 559,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.5.html"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.1.ts_0_832 | // #docregion
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {CrisisListComponent} from './crisis-list/crisis-list.component';
import {HeroListComponent} from './hero-list/hero-list.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
// #docregion appRoutes
const appRoutes: Routes = [
{path: 'crisis-center', component: CrisisListComponent},
{path: 'heroes', component: HeroListComponent},
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
// #enddocregion appRoutes
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 832,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.1.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.ts_0_550 | // #docplaster
// #docregion
import {Component} from '@angular/core';
import {ChildrenOutletContexts} from '@angular/router';
import {slideInAnimation} from './animations';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
animations: [slideInAnimation],
standalone: false,
})
export class AppComponent {
constructor(private contexts: ChildrenOutletContexts) {}
getRouteAnimationData() {
return this.contexts.getContext('primary')?.route?.snapshot?.data?.['animation'];
}
}
| {
"end_byte": 550,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.6.html_0_649 | <!-- #docregion -->
<h1 class="title">Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active" ariaCurrentWhenActive="page">Crisis Center</a>
<a routerLink="/heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Heroes</a>
<a routerLink="/admin" routerLinkActive="active" ariaCurrentWhenActive="page">Admin</a>
<a routerLink="/login" routerLinkActive="active" ariaCurrentWhenActive="page">Login</a>
<a [routerLink]="[{ outlets: { popup: ['compose'] } }]">Contact</a>
</nav>
<div [@routeAnimation]="getAnimationData()">
<router-outlet></router-outlet>
</div>
<router-outlet name="popup"></router-outlet> | {
"end_byte": 649,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.6.html"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.6.ts_0_1336 | // #docplaster
// #docregion, preload-v1
import {NgModule} from '@angular/core';
import {
RouterModule,
Routes,
// #enddocregion preload-v1
PreloadAllModules,
// #docregion preload-v1
} from '@angular/router';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {authGuard} from './auth/auth.guard';
const appRoutes: Routes = [
{
path: 'compose',
component: ComposeMessageComponent,
outlet: 'popup',
},
{
path: 'admin',
loadChildren: () => import('./admin/admin.module').then((m) => m.AdminModule),
canMatch: [authGuard],
},
{
path: 'crisis-center',
loadChildren: () =>
import('./crisis-center/crisis-center.module').then((m) => m.CrisisCenterModule),
},
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
// #docregion forRoot
RouterModule.forRoot(
appRoutes,
// #enddocregion preload-v1
{
enableTracing: true, // <-- debugging purposes only
preloadingStrategy: PreloadAllModules,
},
// #docregion preload-v1
),
// #enddocregion forRoot
],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 1336,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.6.ts"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.2.ts_0_1007 | // #docregion
// #docregion milestone3
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {CrisisListComponent} from './crisis-list/crisis-list.component';
// #enddocregion milestone3
// import { HeroListComponent } from './hero-list/hero-list.component'; // <-- delete this line
// #docregion milestone3
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
const appRoutes: Routes = [
{path: 'crisis-center', component: CrisisListComponent},
// #enddocregion milestone3
// { path: 'heroes', component: HeroListComponent }, // <-- delete this line
// #docregion milestone3
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
// #enddocregion milestone3
| {
"end_byte": 1007,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.2.ts"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.3.ts_0_857 | // #docplaster
// #docregion , v3
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
// #enddocregion v3
import {ComposeMessageComponent} from './compose-message/compose-message.component';
// #docregion v3
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
const appRoutes: Routes = [
// #enddocregion v3
// #docregion compose
{
path: 'compose',
component: ComposeMessageComponent,
outlet: 'popup',
},
// #enddocregion compose
// #docregion v3
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 857,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.3.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.7.html_0_527 | <h1>Angular Router App</h1>
<!-- This nav gives you links to click, which tells the router which route to use (defined in the routes constant in AppRoutingModule) -->
<nav>
<ul>
<li><a routerLink="/first-component" routerLinkActive="active" ariaCurrentWhenActive="page">First Component</a></li>
<li><a routerLink="/second-component" routerLinkActive="active" ariaCurrentWhenActive="page">Second Component</a></li>
</ul>
</nav>
<!-- The routed views render in the <router-outlet>-->
<router-outlet></router-outlet>
| {
"end_byte": 527,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.7.html"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.7.ts_0_362 | import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router'; // CLI imports router
const routes: Routes = []; // sets up routes constant where you define your routes
// configures NgModule imports and exports
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 362,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.7.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.css_0_27 | nav a {
padding: 1rem;
}
| {
"end_byte": 27,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.css"
} |
angular/adev/src/content/examples/router/src/app/app.component.2.ts_0_690 | /* Second Heroes version */
// #docregion
import {Component} from '@angular/core';
// #docregion animation-imports
import {ChildrenOutletContexts} from '@angular/router';
import {slideInAnimation} from './animations';
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
animations: [slideInAnimation],
standalone: false,
})
// #enddocregion animation-imports
// #docregion function-binding
export class AppComponent {
constructor(private contexts: ChildrenOutletContexts) {}
getAnimationData() {
return this.contexts.getContext('primary')?.route?.snapshot?.data?.['animation'];
}
}
// #enddocregion function-binding
| {
"end_byte": 690,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.2.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.1.ts_0_1370 | // #docplaster
// #docregion
// #docregion first-config
import {NgModule} from '@angular/core';
import {FormsModule} from '@angular/forms';
import {BrowserModule} from '@angular/platform-browser';
import {RouterModule, Routes} from '@angular/router';
import {AppComponent} from './app.component';
import {CrisisListComponent} from './crisis-list/crisis-list.component';
import {HeroListComponent} from './hero-list/hero-list.component';
// #enddocregion first-config
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
// #docregion first-config
const appRoutes: Routes = [
{path: 'crisis-center', component: CrisisListComponent},
{path: 'heroes', component: HeroListComponent},
// #enddocregion first-config
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
// #docregion wildcard
{path: '**', component: PageNotFoundComponent}, // #enddocregion wildcard
// #docregion first-config
];
@NgModule({
imports: [
BrowserModule,
FormsModule,
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
],
declarations: [
AppComponent,
HeroListComponent,
CrisisListComponent,
// #enddocregion first-config
PageNotFoundComponent,
// #docregion first-config
],
bootstrap: [AppComponent],
})
export class AppModule {}
// #enddocregion
| {
"end_byte": 1370,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.1.ts"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.8.ts_0_791 | // #docplaster
import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router'; // CLI imports router
// #docregion routes, routes-with-wildcard, redirect
const routes: Routes = [
{path: 'first-component', component: FirstComponent},
{path: 'second-component', component: SecondComponent},
// #enddocregion routes, routes-with-wildcard
{path: '', redirectTo: '/first-component', pathMatch: 'full'}, // redirect to `first-component`
// #docregion routes-with-wildcard
{path: '**', component: PageNotFoundComponent}, // Wildcard route for a 404 page
// #docregion routes
];
// #enddocregion routes, routes-with-wildcard, redirect
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 791,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.8.ts"
} |
angular/adev/src/content/examples/router/src/app/can-deactivate.guard.1.ts_0_954 | // #docregion
import {Observable} from 'rxjs';
import {CanDeactivateFn, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router';
import {CrisisDetailComponent} from './crisis-center/crisis-detail/crisis-detail.component';
export const canDeactivateGuard: CanDeactivateFn<CrisisDetailComponent> = (
component: CrisisDetailComponent,
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot,
): Observable<boolean> | boolean => {
// Get the Crisis Center ID
console.log(route.paramMap.get('id'));
// Get the current URL
console.log(state.url);
// Allow synchronous navigation (`true`) if no crisis or the crisis is unchanged
if (!component.crisis || component.crisis.name === component.editName) {
return true;
}
// Otherwise ask the user with the dialog service and return its
// observable which resolves to true or false when the user decides
return component.dialogService.confirm('Discard changes?');
};
| {
"end_byte": 954,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/can-deactivate.guard.1.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.5.ts_0_891 | // #docplaster
// #docregion
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {AppComponent} from './app.component';
import {AppRoutingModule} from './app-routing.module';
import {HeroesModule} from './heroes/heroes.module';
import {CrisisCenterModule} from './crisis-center/crisis-center.module';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {AdminModule} from './admin/admin.module';
@NgModule({
imports: [
CommonModule,
FormsModule,
HeroesModule,
CrisisCenterModule,
AdminModule,
AppRoutingModule,
],
declarations: [AppComponent, ComposeMessageComponent, PageNotFoundComponent],
bootstrap: [AppComponent],
})
export class AppModule {}
| {
"end_byte": 891,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.5.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.1.html_0_287 | <!-- #docregion -->
<h1>Angular Router</h1>
<nav>
<a routerLink="/crisis-center" routerLinkActive="active" ariaCurrentWhenActive="page">Crisis Center</a>
<a routerLink="/heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Heroes</a>
</nav>
<router-outlet></router-outlet>
| {
"end_byte": 287,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.1.html"
} |
angular/adev/src/content/examples/router/src/app/app-routing.module.9.ts_0_776 | // #docplaster
import {NgModule} from '@angular/core';
import {Routes, RouterModule} from '@angular/router'; // CLI imports router
// #docregion child-routes
const routes: Routes = [
{
path: 'first-component',
component: FirstComponent, // this is the component with the <router-outlet> in the template
children: [
{
path: 'child-a', // child route path
component: ChildAComponent, // child route component that the router renders
},
{
path: 'child-b',
component: ChildBComponent, // another child route component that the router renders
},
],
},
];
// #enddocregion child-routes
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule {}
| {
"end_byte": 776,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app-routing.module.9.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.4.ts_0_1208 | // #docplaster
// #docregion
// #docregion crisis-center-module, admin-module
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {AppComponent} from './app.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {ComposeMessageComponent} from './compose-message/compose-message.component';
import {AppRoutingModule} from './app-routing.module';
import {HeroesModule} from './heroes/heroes.module';
import {CrisisCenterModule} from './crisis-center/crisis-center.module';
// #enddocregion crisis-center-module
import {AdminModule} from './admin/admin.module';
// #docregion crisis-center-module
@NgModule({
imports: [
CommonModule,
FormsModule,
HeroesModule,
CrisisCenterModule,
// #enddocregion crisis-center-module
AdminModule,
// #docregion crisis-center-module
AppRoutingModule,
],
declarations: [
AppComponent,
// #enddocregion crisis-center-module
ComposeMessageComponent,
// #docregion crisis-center-module
PageNotFoundComponent,
],
bootstrap: [AppComponent],
})
export class AppModule {}
// #enddocregion
| {
"end_byte": 1208,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.4.ts"
} |
angular/adev/src/content/examples/router/src/app/animations.ts_0_715 | // #docregion
import {trigger, animateChild, group, transition, animate, style, query} from '@angular/animations';
// Routable animations
export const slideInAnimation = trigger('routeAnimation', [
transition('heroes <=> hero', [
style({position: 'relative'}),
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
left: 0,
width: '100%',
}),
]),
query(':enter', [style({left: '-100%'})]),
query(':leave', animateChild()),
group([
query(':leave', [animate('300ms ease-out', style({left: '100%'}))]),
query(':enter', [animate('300ms ease-out', style({left: '0%'}))]),
]),
query(':enter', animateChild()),
]),
]);
| {
"end_byte": 715,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/animations.ts"
} |
angular/adev/src/content/examples/router/src/app/app.component.3.ts_0_1408 | // #docplaster
import {Component} from '@angular/core';
import {Router} from '@angular/router';
@Component({
selector: 'app-root',
/* Typical link
// #docregion h-anchor
<a [routerLink]="['/heroes']">Heroes</a>
// #enddocregion h-anchor
*/
/* Incomplete Crisis Center link when CC lacks a default
// The link now fails with a "non-terminal link" error
// #docregion cc-anchor-w-default
<a [routerLink]="['/crisis-center']">Crisis Center</a>
// #enddocregion cc-anchor-w-default
*/
/* Crisis Center link when CC lacks a default
<a [routerLink]="['/crisis-center/']">Crisis Center</a>
*/
/* Crisis Center Detail link
// #docregion Dragon-anchor
<a [routerLink]="['/crisis-center', 1]">Dragon Crisis</a>
// #enddocregion Dragon-anchor
*/
/* Crisis Center link with optional query params
// #docregion cc-query-params
<a [routerLink]="['/crisis-center', { foo: 'foo' }]">Crisis Center</a>
// #enddocregion cc-query-params
*/
// #docregion template
template: `
<h1 class="title">Angular Router</h1>
<nav>
<a [routerLink]="['/crisis-center']">Crisis Center</a>
<a [routerLink]="['/crisis-center/1', { foo: 'foo' }]">Dragon Crisis</a>
<a [routerLink]="['/crisis-center/2']">Shark Crisis</a>
</nav>
<router-outlet></router-outlet>
`,
standalone: false,
})
export class AppComponent {}
| {
"end_byte": 1408,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.component.3.ts"
} |
angular/adev/src/content/examples/router/src/app/app.module.0.ts_0_1140 | // NEVER USED. For docs only. Should compile though
// #docplaster
import {NgModule} from '@angular/core';
import {RouterModule, Routes} from '@angular/router';
import {HeroListComponent} from './hero-list/hero-list.component';
import {CrisisListComponent} from './crisis-list/crisis-list.component';
import {PageNotFoundComponent} from './page-not-found/page-not-found.component';
import {PageNotFoundComponent as HeroDetailComponent} from './page-not-found/page-not-found.component';
// #docregion
const appRoutes: Routes = [
{path: 'crisis-center', component: CrisisListComponent},
{path: 'hero/:id', component: HeroDetailComponent},
{
path: 'heroes',
component: HeroListComponent,
data: {title: 'Heroes List'},
},
{path: '', redirectTo: '/heroes', pathMatch: 'full'},
{path: '**', component: PageNotFoundComponent},
];
@NgModule({
imports: [
RouterModule.forRoot(
appRoutes,
{enableTracing: true}, // <-- debugging purposes only
),
// other imports here
],
// #enddocregion
/*
// #docregion
...
})
export class AppModule { }
// #enddocregion
*/
})
export class AppModule0 {}
| {
"end_byte": 1140,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/router/src/app/app.module.0.ts"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.