_id
stringlengths 21
254
| text
stringlengths 1
93.7k
| metadata
dict |
---|---|---|
angular/adev/src/content/examples/accessibility/src/index.html_0_317 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Accessibility Example</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
| {
"end_byte": 317,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/src/index.html"
} |
angular/adev/src/content/examples/accessibility/src/main.ts_0_275 | import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [provideProtractorTestingSupport()],
}).catch((err) => console.error(err));
| {
"end_byte": 275,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/src/main.ts"
} |
angular/adev/src/content/examples/accessibility/src/app/app.component.html_0_490 | <h1>Accessibility Example</h1>
<!-- #docregion template -->
<label for="progress-value">
Enter an example progress value
<input id="progress-value" type="number" min="0" max="100"
[value]="progress" (input)="setProgress($event)">
</label>
<!-- The user of the progressbar sets an aria-label to communicate what the progress means. -->
<app-example-progressbar [value]="progress" aria-label="Example of a progress bar">
</app-example-progressbar>
<!-- #enddocregion template -->
| {
"end_byte": 490,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/src/app/app.component.html"
} |
angular/adev/src/content/examples/accessibility/src/app/app.component.ts_0_437 | import {Component} from '@angular/core';
import {ExampleProgressbarComponent} from './progress-bar.component';
@Component({
standalone: true,
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
imports: [ExampleProgressbarComponent],
})
export class AppComponent {
progress = 0;
setProgress($event: Event) {
this.progress = +($event.target as HTMLInputElement).value;
}
}
| {
"end_byte": 437,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/src/app/app.component.ts"
} |
angular/adev/src/content/examples/accessibility/src/app/progress-bar.component.css_4_208 | :host {
display: block;
width: 300px;
height: 25px;
border: 1px solid black;
margin-top: 16px;
}
.bar {
background: blue;
height: 100%;
} | {
"end_byte": 208,
"start_byte": 4,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/src/app/progress-bar.component.css"
} |
angular/adev/src/content/examples/accessibility/src/app/progress-bar.component.ts_0_850 | /* eslint-disable @angular-eslint/no-host-metadata-property */
// #docregion progressbar-component
import {Component, Input} from '@angular/core';
/**
* Example progressbar component.
*/
@Component({
standalone: true,
selector: 'app-example-progressbar',
template: '<div class="bar" [style.width.%]="value"></div>',
styleUrls: ['./progress-bar.component.css'],
host: {
// Sets the role for this component to "progressbar"
role: 'progressbar',
// Sets the minimum and maximum values for the progressbar role.
'aria-valuemin': '0',
'aria-valuemax': '100',
// Binding that updates the current value of the progressbar.
'[attr.aria-valuenow]': 'value',
},
})
export class ExampleProgressbarComponent {
/** Current value of the progressbar. */
@Input() value = 0;
}
// #enddocregion progressbar-component
| {
"end_byte": 850,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/src/app/progress-bar.component.ts"
} |
angular/adev/src/content/examples/built-in-directives/BUILD.bazel_0_180 | package(default_visibility = ["//visibility:public"])
exports_files([
"src/app/app.component.html",
"src/app/app.component.ts",
"src/app/item-switch.component.ts",
])
| {
"end_byte": 180,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/BUILD.bazel"
} |
angular/adev/src/content/examples/built-in-directives/e2e/src/app.e2e-spec.ts_0_2688 | import {browser, element, by} from 'protractor';
describe('Built-in Directives', () => {
beforeAll(() => browser.get(''));
it('should have title Built-in Directives', async () => {
const title = element.all(by.css('h1')).get(0);
expect(await title.getText()).toEqual('Built-in Directives');
});
it('should change first Teapot header', async () => {
const firstLabel = element.all(by.css('p')).get(0);
const firstInput = element.all(by.css('input')).get(0);
expect(await firstLabel.getText()).toEqual('Current item name: Teapot');
await firstInput.sendKeys('abc');
expect(await firstLabel.getText()).toEqual('Current item name: Teapotabc');
});
it('should modify sentence when modified checkbox checked', async () => {
const modifiedChkbxLabel = element.all(by.css('input[type="checkbox"]')).get(1);
const modifiedSentence = element.all(by.css('div')).get(1);
await modifiedChkbxLabel.click();
expect(await modifiedSentence.getText()).toContain('modified');
});
it('should modify sentence when normal checkbox checked', async () => {
const normalChkbxLabel = element.all(by.css('input[type="checkbox"]')).get(4);
const normalSentence = element.all(by.css('div')).get(7);
await normalChkbxLabel.click();
expect(await normalSentence.getText()).toContain('normal weight and, extra large');
});
it('should toggle app-item-detail', async () => {
const toggleButton = element.all(by.css('button')).get(3);
const toggledDiv = element.all(by.css('app-item-detail')).get(0);
await toggleButton.click();
expect(await toggledDiv.isDisplayed()).toBe(true);
});
it('should hide app-item-detail', async () => {
const hiddenMessage = element.all(by.css('p')).get(10);
const hiddenDiv = element.all(by.css('app-item-detail')).get(2);
expect(await hiddenMessage.getText()).toContain('in the DOM');
expect(await hiddenDiv.isDisplayed()).toBe(true);
});
it('should have 10 lists each containing the string Teapot', async () => {
const listDiv = element.all(by.cssContainingText('.box', 'Teapot'));
expect(await listDiv.count()).toBe(10);
});
it('should switch case', async () => {
const tvRadioButton = element.all(by.css('input[type="radio"]')).get(3);
const tvDiv = element(by.css('app-lost-item'));
const fishbowlRadioButton = element.all(by.css('input[type="radio"]')).get(4);
const fishbowlDiv = element(by.css('app-unknown-item'));
await tvRadioButton.click();
expect(await tvDiv.getText()).toContain('Television');
await fishbowlRadioButton.click();
expect(await fishbowlDiv.getText()).toContain('mysterious');
});
});
| {
"end_byte": 2688,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/built-in-directives/src/index.html_0_303 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>BuiltInDirectives</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
| {
"end_byte": 303,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/index.html"
} |
angular/adev/src/content/examples/built-in-directives/src/main.ts_0_275 | import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [provideProtractorTestingSupport()],
}).catch((err) => console.error(err));
| {
"end_byte": 275,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/main.ts"
} |
angular/adev/src/content/examples/built-in-directives/src/app/app.component.html_0_6612 | <h1>Built-in Directives</h1>
<h2>Built-in attribute directives</h2>
<h3 id="ngModel">NgModel (two-way) Binding</h3>
<fieldset><h4>NgModel examples</h4>
<p>Current item name: {{ currentItem.name }}</p>
<p>
<label for="without">without NgModel:</label>
<input [value]="currentItem.name" (input)="currentItem.name=getValue($event)" id="without">
</p>
<p>
<!-- #docregion NgModel-1 -->
<label for="example-ngModel">[(ngModel)]:</label>
<input [(ngModel)]="currentItem.name" id="example-ngModel">
<!-- #enddocregion NgModel-1 -->
</p>
<p>
<label for="example-change">(ngModelChange)="...name=$event":</label>
<input [ngModel]="currentItem.name" (ngModelChange)="currentItem.name=$event" id="example-change">
</p>
<p>
<label for="example-uppercase">(ngModelChange)="setUppercaseName($event)"
<!-- #docregion uppercase -->
<input [ngModel]="currentItem.name" (ngModelChange)="setUppercaseName($event)" id="example-uppercase">
<!-- #enddocregion uppercase -->
</label>
</p>
</fieldset>
<hr><h2 id="ngClass">NgClass Binding</h2>
<p>currentClasses is {{ currentClasses | json }}</p>
<!-- #docregion NgClass-1 -->
<div [ngClass]="currentClasses">This div is initially saveable, unchanged, and special.</div>
<!-- #enddocregion NgClass-1 -->
<ul>
<li>
<label for="saveable">saveable</label>
<input type="checkbox" [(ngModel)]="canSave" id="saveable">
</li>
<li>
<label for="modified">modified:</label>
<input type="checkbox" [value]="!isUnchanged" (change)="isUnchanged=!isUnchanged" id="modified"></li>
<li>
<label for="special">special: <input type="checkbox" [(ngModel)]="isSpecial" id="special"></label>
</li>
</ul>
<button type="button" (click)="setCurrentClasses()">Refresh currentClasses</button>
<div [ngClass]="currentClasses">
This div should be {{ canSave ? "": "not"}} saveable,
{{ isUnchanged ? "unchanged" : "modified" }} and
{{ isSpecial ? "": "not"}} special after clicking "Refresh".</div>
<br><br>
<!-- #docregion special-div -->
<!-- toggle the "special" class on/off with a property -->
<div [ngClass]="isSpecial ? 'special' : ''">This div is special</div>
<!-- #enddocregion special-div -->
<div class="helpful study course">Helpful study course</div>
<div [ngClass]="{'helpful':false, 'study':true, 'course':true}">Study course</div>
<!-- NgStyle binding -->
<hr><h3>NgStyle Binding</h3>
<div [style.font-size]="isSpecial ? 'x-large' : 'smaller'">
This div is x-large or smaller.
</div>
<h4>[ngStyle] binding to currentStyles - CSS property names</h4>
<p>currentStyles is {{ currentStyles | json }}</p>
<!-- #docregion NgStyle-2 -->
<div [ngStyle]="currentStyles">
This div is initially italic, normal weight, and extra large (24px).
</div>
<!-- #enddocregion NgStyle-2 -->
<br>
<label for="canSave">italic: <input id="canSave" type="checkbox" [(ngModel)]="canSave"></label> |
<label for="isUnchanged">normal: <input id="isUnchanged" type="checkbox" [(ngModel)]="isUnchanged"></label> |
<label for="isSpecial">xlarge: <input id="isSpecial" type="checkbox" [(ngModel)]="isSpecial"></label>
<button type="button" (click)="setCurrentStyles()">Refresh currentStyles</button>
<br><br>
<div [ngStyle]="currentStyles">
This div should be {{ canSave ? "italic": "plain"}},
{{ isUnchanged ? "normal weight" : "bold" }} and,
{{ isSpecial ? "extra large": "normal size"}} after clicking "Refresh".</div>
<hr>
<h2>Built-in structural directives</h2>
<h3 id="ngIf">NgIf Binding</h3>
<div>
<p>If isActive is true, app-item-detail will render: </p>
<!-- #docregion NgIf-1 -->
<app-item-detail *ngIf="isActive" [item]="item"></app-item-detail>
<!-- #enddocregion NgIf-1 -->
<button type="button" (click)="isActiveToggle()">Toggle app-item-detail</button>
</div>
<p>If currentCustomer isn't null, say hello to Laura:</p>
<!-- #docregion NgIf-2 -->
<div *ngIf="currentCustomer">Hello, {{ currentCustomer.name }}</div>
<!-- #enddocregion NgIf-2 -->
<p>nullCustomer is null by default. NgIf guards against null. Give it a value to show it:</p>
<!-- #docregion NgIf-2b -->
<div *ngIf="nullCustomer">Hello, <span>{{ nullCustomer }}</span></div>
<!-- #enddocregion NgIf-2b -->
<button type="button" (click)="giveNullCustomerValue()">Give nullCustomer a value</button>
<h4>NgIf binding with template (no *)</h4>
<ng-template [ngIf]="currentItem">Add {{ currentItem.name }} with template</ng-template>
<hr>
<h4>Show/hide vs. NgIf</h4>
<!-- isSpecial is true -->
<div [class.hidden]="!isSpecial">Show with class</div>
<div [class.hidden]="isSpecial">Hide with class</div>
<p>ItemDetail is in the DOM but hidden</p>
<app-item-detail [class.hidden]="isSpecial"></app-item-detail>
<div [style.display]="isSpecial ? 'block' : 'none'">Show with style</div>
<div [style.display]="isSpecial ? 'none' : 'block'">Hide with style</div>
<hr>
<h2 id="ngFor">NgFor Binding</h2>
<div class="box">
<!-- #docregion NgFor-1, NgFor-1-2 -->
<div *ngFor="let item of items">{{ item.name }}</div>
<!-- #enddocregion NgFor-1, NgFor-1-2 -->
</div>
<p>*ngFor with ItemDetailComponent element</p>
<div class="box">
<!-- #docregion NgFor-2, NgFor-1-2 -->
<app-item-detail *ngFor="let item of items" [item]="item"></app-item-detail>
<!-- #enddocregion NgFor-2, NgFor-1-2 -->
</div>
<h4 id="ngFor-index">*ngFor with index</h4>
<p>with <em>semi-colon</em> separator</p>
<div class="box">
<!-- #docregion NgFor-3 -->
<div *ngFor="let item of items; let i=index">{{ i + 1 }} - {{ item.name }}</div>
<!-- #enddocregion NgFor-3 -->
</div>
<p>with <em>comma</em> separator</p>
<div class="box">
<div *ngFor="let item of items, let i=index">{{ i + 1 }} - {{ item.name }}</div>
</div>
<h4 id="ngFor-trackBy">*ngFor trackBy</h4>
<button type="button" (click)="resetList()">Reset items</button>
<button type="button" (click)="changeIds()">Change ids</button>
<button type="button" (click)="clearTrackByCounts()">Clear counts</button>
<p><em>without</em> trackBy</p>
<div class="box">
<div #noTrackBy *ngFor="let item of items">({{ item.id }}) {{ item.name }}</div>
<div id="noTrackByCnt" *ngIf="itemsNoTrackByCount" >
Item DOM elements change #{{ itemsNoTrackByCount }} without trackBy
</div>
</div>
<p>with trackBy</p>
<div class="box">
<div #withTrackBy *ngFor="let item of items; trackBy: trackByItems">({{ item.id }}) {{ item.name }}</div>
<div id="withTrackByCnt" *ngIf="itemsWithTrackByCount">
Item DOM elements change #{{ itemsWithTrackByCount }} with trackBy
</div>
</div>
<br><br><br>
| {
"end_byte": 6612,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/app.component.html"
} |
angular/adev/src/content/examples/built-in-directives/src/app/app.component.html_6612_8379 | <p>with trackBy and <em>semi-colon</em> separator</p>
<div class="box">
<!-- #docregion trackBy -->
<div *ngFor="let item of items; trackBy: trackByItems">
({{ item.id }}) {{ item.name }}
</div>
<!-- #enddocregion trackBy -->
</div>
<p>with trackBy and <em>comma</em> separator</p>
<div class="box">
<div *ngFor="let item of items, trackBy: trackByItems">({{ item.id }}) {{ item.name }}</div>
</div>
<p>with trackBy and <em>space</em> separator</p>
<div class="box">
<div *ngFor="let item of items trackBy: trackByItems">({{ item.id }}) {{ item.name }}</div>
</div>
<p>with <em>generic</em> trackById function</p>
<div class="box">
<div *ngFor="let item of items, trackBy: trackById">({{ item.id }}) {{ item.name }}</div>
</div>
<hr><h2>NgSwitch Binding</h2>
<p>Pick your favorite item</p>
<div>
<label for="item-{{i}}" *ngFor="let i of items">
<div><input id="item-{{i}}"type="radio" name="items" [(ngModel)]="currentItem" [value]="i">{{ i.name }}
</div>
</label>
</div>
<!-- #docregion NgSwitch -->
<div [ngSwitch]="currentItem.feature">
<app-stout-item *ngSwitchCase="'stout'" [item]="currentItem"></app-stout-item>
<app-device-item *ngSwitchCase="'slim'" [item]="currentItem"></app-device-item>
<app-lost-item *ngSwitchCase="'vintage'" [item]="currentItem"></app-lost-item>
<app-best-item *ngSwitchCase="'bright'" [item]="currentItem"></app-best-item>
<!-- #enddocregion NgSwitch -->
<!-- #docregion NgSwitch-div -->
<div *ngSwitchCase="'bright'">Are you as bright as {{ currentItem.name }}?</div>
<!-- #enddocregion NgSwitch-div -->
<!-- #docregion NgSwitch -->
<app-unknown-item *ngSwitchDefault [item]="currentItem"></app-unknown-item>
</div>
<!-- #enddocregion NgSwitch --> | {
"end_byte": 8379,
"start_byte": 6612,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/app.component.html"
} |
angular/adev/src/content/examples/built-in-directives/src/app/item.ts_0_517 | export class Item {
static nextId = 0;
static items: Item[] = [
new Item(0, 'Teapot', 'stout'),
new Item(1, 'Lamp', 'bright'),
new Item(2, 'Phone', 'slim'),
new Item(3, 'Television', 'vintage'),
new Item(4, 'Fishbowl'),
];
constructor(
public id: number,
public name?: string,
public feature?: string,
public url?: string,
public rate = 100,
) {
this.id = id ? id : Item.nextId++;
}
clone(): Item {
return Object.assign(new Item(this.id), this);
}
}
| {
"end_byte": 517,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/item.ts"
} |
angular/adev/src/content/examples/built-in-directives/src/app/app.component.ts_0_5388 | import {Component, OnInit} from '@angular/core';
import {JsonPipe} from '@angular/common';
// #docregion import-ng-if
import {NgIf} from '@angular/common';
// #enddocregion import-ng-if
// #docregion import-ng-for
import {NgFor} from '@angular/common';
// #enddocregion import-ng-for
// #docregion import-ng-switch
import {NgSwitch, NgSwitchCase, NgSwitchDefault} from '@angular/common';
// #enddocregion import-ng-switch
// #docregion import-ng-style
import {NgStyle} from '@angular/common';
// #enddocregion import-ng-style
// #docregion import-ng-class
import {NgClass} from '@angular/common';
// #enddocregion import-ng-class
// #docregion import-forms-module
import {FormsModule} from '@angular/forms';
// #enddocregion import-forms-module
import {Item} from './item';
import {ItemDetailComponent} from './item-detail/item-detail.component';
import {ItemSwitchComponents} from './item-switch.component';
import {StoutItemComponent} from './item-switch.component';
// #docregion import-ng-if, import-ng-for, import-ng-switch, import-ng-style, import-ng-class, import-forms-module
@Component({
standalone: true,
// #enddocregion import-ng-if, import-ng-for, import-ng-switch, import-ng-style, import-ng-class, import-forms-module
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
imports: [
// #docregion import-ng-if
NgIf, // <-- import into the component
// #enddocregion import-ng-if
// #docregion import-ng-for
NgFor, // <-- import into the component
// #enddocregion import-ng-for
// #docregion import-ng-style
NgStyle, // <-- import into the component
// #enddocregion import-ng-style
// #docregion import-ng-switch
NgSwitch, // <-- import into the component
NgSwitchCase,
NgSwitchDefault,
// #enddocregion import-ng-switch
// #docregion import-ng-class
NgClass, // <-- import into the component
// #enddocregion import-ng-class
// #docregion import-forms-module
FormsModule, // <--- import into the component
// #enddocregion import-forms-module
JsonPipe,
ItemDetailComponent,
ItemSwitchComponents,
StoutItemComponent,
// #docregion import-ng-if, import-ng-for, import-ng-style, import-ng-switch, import-ng-class, import-forms-module
],
})
export class AppComponent implements OnInit {
// #enddocregion import-ng-if, import-ng-for, import-ng-style, import-ng-switch, import-ng-class, import-forms-module
canSave = true;
isSpecial = true;
isUnchanged = true;
isActive = true;
nullCustomer: string | null = null;
currentCustomer = {
name: 'Laura',
};
item!: Item; // defined to demonstrate template context precedence
items: Item[] = [];
// #docregion item
currentItem!: Item;
// #enddocregion item
// trackBy change counting
itemsNoTrackByCount = 0;
itemsWithTrackByCount = 0;
itemsWithTrackByCountReset = 0;
itemIdIncrement = 1;
// #docregion setClasses
currentClasses: Record<string, boolean> = {};
// #enddocregion setClasses
// #docregion setStyles
currentStyles: Record<string, string> = {};
// #enddocregion setStyles
ngOnInit() {
this.resetItems();
this.setCurrentClasses();
this.setCurrentStyles();
this.itemsNoTrackByCount = 0;
}
setUppercaseName(name: string) {
this.currentItem.name = name.toUpperCase();
}
// #docregion setClasses
setCurrentClasses() {
// CSS classes: added/removed per current state of component properties
this.currentClasses = {
saveable: this.canSave,
modified: !this.isUnchanged,
special: this.isSpecial,
};
}
// #enddocregion setClasses
// #docregion setStyles
setCurrentStyles() {
// CSS styles: set per current state of component properties
this.currentStyles = {
'font-style': this.canSave ? 'italic' : 'normal',
'font-weight': !this.isUnchanged ? 'bold' : 'normal',
'font-size': this.isSpecial ? '24px' : '12px',
};
}
// #enddocregion setStyles
isActiveToggle() {
this.isActive = !this.isActive;
}
giveNullCustomerValue() {
this.nullCustomer = 'Kelly';
}
resetItems() {
this.items = Item.items.map((item) => item.clone());
this.currentItem = this.items[0];
this.item = this.currentItem;
}
resetList() {
this.resetItems();
this.itemsWithTrackByCountReset = 0;
this.itemsNoTrackByCount = ++this.itemsNoTrackByCount;
}
changeIds() {
this.items.forEach((i) => (i.id += 1 * this.itemIdIncrement));
this.itemsWithTrackByCountReset = -1;
this.itemsNoTrackByCount = ++this.itemsNoTrackByCount;
this.itemsWithTrackByCount = ++this.itemsWithTrackByCount;
}
clearTrackByCounts() {
this.resetItems();
this.itemsNoTrackByCount = 0;
this.itemsWithTrackByCount = 0;
this.itemIdIncrement = 1;
}
// #docregion trackByItems
trackByItems(index: number, item: Item): number {
return item.id;
}
// #enddocregion trackByItems
trackById(index: number, item: any): number {
return item.id;
}
getValue(event: Event): string {
return (event.target as HTMLInputElement).value;
}
// #docregion import-ng-if, import-ng-for, import-ng-switch, import-ng-style, import-ng-class, import-forms-module
}
// #enddocregion import-ng-if, import-ng-for, import-ng-switch, import-ng-style, import-ng-class, import-forms-module
| {
"end_byte": 5388,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/app.component.ts"
} |
angular/adev/src/content/examples/built-in-directives/src/app/app.component.css_1_787 | button {
font-size: 100%;
margin: 0 2px;
}
div[ng-reflect-ng-switch], app-unknown-item {
margin: .5rem 0;
display: block;
}
#noTrackByCnt,
#withTrackByCnt {
color: darkred;
max-width: 450px;
margin: 4px;
}
img {
height: 100px;
}
.box {
border: 1px solid black;
padding: 6px;
max-width: 450px;
}
.child-div {
margin-left: 1em;
font-weight: normal;
}
.context {
margin-left: 1em;
}
.hidden {
display: none;
}
.parent-div {
margin-top: 1em;
font-weight: bold;
}
.course {
font-weight: bold;
font-size: x-large;
}
.helpful {
color: red;
}
.saveable {
color: limegreen;
}
.study,
.modified {
font-family: "Brush Script MT", cursive;
font-size: 2rem;
}
.toe {
margin-left: 1em;
font-style: italic;
}
.to-toc {
margin-top: 10px;
display: block;
}
| {
"end_byte": 787,
"start_byte": 1,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/app.component.css"
} |
angular/adev/src/content/examples/built-in-directives/src/app/item-switch.component.ts_0_1319 | import {Component, Input} from '@angular/core';
import {Item} from './item';
@Component({
standalone: true,
selector: 'app-stout-item',
template: "I'm a little {{item.name}}, short and stout!",
})
// #docregion input
export class StoutItemComponent {
@Input() item!: Item;
}
// #enddocregion input
@Component({
standalone: true,
selector: 'app-best-item',
template: 'This is the brightest {{item.name}} in town.',
})
export class BestItemComponent {
@Input() item!: Item;
}
@Component({
standalone: true,
selector: 'app-device-item',
template: 'Which is the slimmest {{item.name}}?',
})
export class DeviceItemComponent {
@Input() item!: Item;
}
@Component({
standalone: true,
selector: 'app-lost-item',
template: 'Has anyone seen my {{item.name}}?',
})
export class LostItemComponent {
@Input() item!: Item;
}
@Component({
standalone: true,
selector: 'app-unknown-item',
template: '{{message}}',
})
export class UnknownItemComponent {
@Input() item!: Item;
get message() {
return this.item && this.item.name
? `${this.item.name} is strange and mysterious.`
: 'A mystery wrapped in a fishbowl.';
}
}
export const ItemSwitchComponents = [
StoutItemComponent,
BestItemComponent,
DeviceItemComponent,
LostItemComponent,
UnknownItemComponent,
];
| {
"end_byte": 1319,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/item-switch.component.ts"
} |
angular/adev/src/content/examples/built-in-directives/src/app/item-detail/item-detail.component.html_0_44 | <div>
<span>{{ item.name }}</span>
</div>
| {
"end_byte": 44,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/item-detail/item-detail.component.html"
} |
angular/adev/src/content/examples/built-in-directives/src/app/item-detail/item-detail.component.ts_0_301 | import {Component, Input} from '@angular/core';
import {Item} from '../item';
@Component({
standalone: true,
selector: 'app-item-detail',
templateUrl: './item-detail.component.html',
styleUrls: ['./item-detail.component.css'],
})
export class ItemDetailComponent {
@Input() item!: Item;
}
| {
"end_byte": 301,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/built-in-directives/src/app/item-detail/item-detail.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/BUILD.bazel_0_106 | package(default_visibility = ["//visibility:public"])
exports_files(["src/app/tree-shaking/service.ts"])
| {
"end_byte": 106,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/BUILD.bazel"
} |
angular/adev/src/content/examples/dependency-injection/e2e/src/app.e2e-spec.ts_0_7534 | import {browser, element, by, ElementFinder} from 'protractor';
describe('Dependency Injection Tests', () => {
let expectedMsg: string;
let expectedMsgRx: RegExp;
beforeAll(() => browser.get(''));
describe('Cars:', () => {
it('DI car displays as expected', async () => {
expectedMsg = 'DI car with 4 cylinders and Flintstone tires.';
expect(await element(by.css('#di')).getText()).toEqual(expectedMsg);
});
it('No DI car displays as expected', async () => {
expectedMsg = 'No DI car with 4 cylinders and Flintstone tires.';
expect(await element(by.css('#nodi')).getText()).toEqual(expectedMsg);
});
it('Injector car displays as expected', async () => {
expectedMsg = 'Injector car with 4 cylinders and Flintstone tires.';
expect(await element(by.css('#injector')).getText()).toEqual(expectedMsg);
});
it('Factory car displays as expected', async () => {
expectedMsg = 'Factory car with 4 cylinders and Flintstone tires.';
expect(await element(by.css('#factory')).getText()).toEqual(expectedMsg);
});
it('Simple car displays as expected', async () => {
expectedMsg = 'Simple car with 4 cylinders and Flintstone tires.';
expect(await element(by.css('#simple')).getText()).toEqual(expectedMsg);
});
it('Super car displays as expected', async () => {
expectedMsg = 'Super car with 12 cylinders and Flintstone tires.';
expect(await element(by.css('#super')).getText()).toEqual(expectedMsg);
});
it('Test car displays as expected', async () => {
expectedMsg = 'Test car with 8 cylinders and YokoGoodStone tires.';
expect(await element(by.css('#test')).getText()).toEqual(expectedMsg);
});
});
describe('Other Injections:', () => {
it('DI car displays as expected', async () => {
expectedMsg = 'DI car with 4 cylinders and Flintstone tires.';
expect(await element(by.css('#car')).getText()).toEqual(expectedMsg);
});
it('Hero displays as expected', async () => {
expectedMsg = 'Dr. Nice';
expect(await element(by.css('#hero')).getText()).toEqual(expectedMsg);
});
it('Optional injection displays as expected', async () => {
expectedMsg = "R.O.U.S.'s? I don't think they exist!";
expect(await element(by.css('#rodent')).getText()).toEqual(expectedMsg);
});
});
describe('Tests:', () => {
it('Tests display as expected', async () => {
expectedMsgRx = /Tests passed/;
expect(await element(by.css('#tests')).getText()).toMatch(expectedMsgRx);
});
});
describe('Provider variations:', () => {
it('P1 (class) displays as expected', async () => {
expectedMsg = 'Hello from logger provided with Logger class';
expect(await element(by.css('#p1')).getText()).toEqual(expectedMsg);
});
it('P3 (provide) displays as expected', async () => {
expectedMsg = 'Hello from logger provided with useClass:Logger';
expect(await element(by.css('#p3')).getText()).toEqual(expectedMsg);
});
it('P4 (useClass:BetterLogger) displays as expected', async () => {
expectedMsg = 'Hello from logger provided with useClass:BetterLogger';
expect(await element(by.css('#p4')).getText()).toEqual(expectedMsg);
});
it('P5 (useClass:EvenBetterLogger - dependency) displays as expected', async () => {
expectedMsg = 'Message to Bob: Hello from EvenBetterlogger';
expect(await element(by.css('#p5')).getText()).toEqual(expectedMsg);
});
it('P6a (no alias) displays as expected', async () => {
expectedMsg = 'Hello OldLogger (but we want NewLogger)';
expect(await element(by.css('#p6a')).getText()).toEqual(expectedMsg);
});
it('P6b (alias) displays as expected', async () => {
expectedMsg = 'Hello from NewLogger (via aliased OldLogger)';
expect(await element(by.css('#p6b')).getText()).toEqual(expectedMsg);
});
it('P7 (useValue) displays as expected', async () => {
expectedMsg = 'Silent logger says "Shhhhh!". Provided via "useValue"';
expect(await element(by.css('#p7')).getText()).toEqual(expectedMsg);
});
it('P8 (useFactory) displays as expected', async () => {
expectedMsg = 'Hero service injected successfully via heroServiceProvider';
expect(await element(by.css('#p8')).getText()).toEqual(expectedMsg);
});
it('P9 (InjectionToken) displays as expected', async () => {
expectedMsg = 'APP_CONFIG Application title is Dependency Injection';
expect(await element(by.css('#p9')).getText()).toEqual(expectedMsg);
});
it('P10 (optional dependency) displays as expected', async () => {
expectedMsg = 'Optional logger was not available';
expect(await element(by.css('#p10')).getText()).toEqual(expectedMsg);
});
});
describe('User/Heroes:', () => {
it('User is Bob - unauthorized', async () => {
expectedMsgRx = /Bob, is not authorized/;
expect(await element(by.css('#user')).getText()).toMatch(expectedMsgRx);
});
it('should have button', async () => {
expect(
await element.all(by.cssContainingText('button', 'Next User')).get(0).isDisplayed(),
).toBe(true, "'Next User' button should be displayed");
});
it('unauthorized user should have multiple unauthorized heroes', async () => {
const heroes = element.all(by.css('#unauthorized app-hero-list div'));
expect(await heroes.count()).toBeGreaterThan(0);
});
it('unauthorized user should have no secret heroes', async () => {
const heroes = element.all(by.css('#unauthorized app-hero-list div'));
expect(await heroes.count()).toBeGreaterThan(0);
const filteredHeroes = heroes.filter(async (elem) => /secret/.test(await elem.getText()));
expect(await filteredHeroes.count()).toEqual(0);
});
it('unauthorized user should have no authorized heroes listed', async () => {
expect(await element.all(by.css('#authorized app-hero-list div')).count()).toEqual(0);
});
describe('after button click', () => {
beforeAll(async () => {
const buttonEle = element.all(by.cssContainingText('button', 'Next User')).get(0);
await buttonEle.click();
});
it('User is Alice - authorized', async () => {
expectedMsgRx = /Alice, is authorized/;
expect(await element(by.css('#user')).getText()).toMatch(expectedMsgRx);
});
it('authorized user should have multiple authorized heroes ', async () => {
const heroes = element.all(by.css('#authorized app-hero-list div'));
expect(await heroes.count()).toBeGreaterThan(0);
});
it('authorized user should have multiple authorized heroes with tree-shakeable HeroesService', async () => {
const heroes = element.all(by.css('#tspAuthorized app-hero-list div'));
expect(await heroes.count()).toBeGreaterThan(0);
});
it('authorized user should have secret heroes', async () => {
const heroes = element.all(by.css('#authorized app-hero-list div'));
expect(await heroes.count()).toBeGreaterThan(0);
const filteredHeroes = heroes.filter(async (elem) => /secret/.test(await elem.getText()));
expect(await filteredHeroes.count()).toBeGreaterThan(0);
});
it('authorized user should have no unauthorized heroes listed', async () => {
expect(await element.all(by.css('#unauthorized app-hero-list div')).count()).toEqual(0);
});
});
});
});
| {
"end_byte": 7534,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/index.html_0_287 | <!-- #docregion -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>Dependency Injection</title>
<base href="/">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
| {
"end_byte": 287,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/index.html"
} |
angular/adev/src/content/examples/dependency-injection/src/main.ts_0_204 | import {bootstrapApplication} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
import appConfig from './app/app.config';
bootstrapApplication(AppComponent, appConfig);
| {
"end_byte": 204,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/main.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/providers.module.ts_0_698 | import {NgModule} from '@angular/core';
import {
Provider1Component,
Provider3Component,
Provider4Component,
Provider5Component,
Provider6aComponent,
Provider6bComponent,
Provider7Component,
Provider8Component,
Provider9Component,
Provider10Component,
ProvidersComponent,
} from './providers.component';
@NgModule({
declarations: [
Provider1Component,
Provider3Component,
Provider4Component,
Provider5Component,
Provider6aComponent,
Provider6bComponent,
Provider7Component,
Provider8Component,
Provider9Component,
Provider10Component,
ProvidersComponent,
],
exports: [ProvidersComponent],
})
export class ProvidersModule {}
| {
"end_byte": 698,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/providers.module.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/app.component.1.ts_0_429 | // #docregion
import {Component} from '@angular/core';
import {CarComponent} from './car/car.component';
import {HeroesComponent} from './heroes/heroes.component';
@Component({
standalone: true,
selector: 'app-root',
template: `
<h1>{{title}}</h1>
<app-car></app-car>
<app-heroes></app-heroes>
`,
imports: [CarComponent, HeroesComponent],
})
export class AppComponent {
title = 'Dependency Injection';
}
| {
"end_byte": 429,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/app.component.1.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/app-config.ts_0_275 | /*
Must put this interface in its own file instead of app.config.ts
or else TypeScript gives a (bogus) warning:
WARNING in ./src/app/... .ts
"export 'AppConfig' was not found in './app.config'
*/
export interface AppConfig {
apiEndpoint: string;
title: string;
}
| {
"end_byte": 275,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/app-config.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/test.component.ts_0_1487 | // Simulate a simple test
// Reader should look to the testing chapter for the real thing
import {Component} from '@angular/core';
import {Hero} from './heroes/hero';
import {HeroService} from './heroes/hero.service';
import {HeroListComponent} from './heroes/hero-list.component';
@Component({
standalone: true,
selector: 'app-tests',
template: `
<h2>Tests</h2>
<p id="tests">Tests {{results.pass}}: {{results.message}}</p>
`,
})
export class TestComponent {
results = runTests();
}
/////////////////////////////////////
function runTests() {
const expectedHeroes = [{name: 'A'}, {name: 'B'}];
const mockService = {getHeroes: () => expectedHeroes} as HeroService;
it('should have heroes when HeroListComponent created', () => {
// Pass the mock to the constructor as the Angular injector would
const component = new HeroListComponent(mockService);
expect(component.heroes.length).toEqual(expectedHeroes.length);
});
return testResults;
}
//////////////////////////////////
// Fake Jasmine infrastructure
let testName: string;
let testResults: {pass: string; message: string};
function expect(actual: any) {
return {
toEqual: (expected: any) => {
testResults =
actual === expected
? {pass: 'passed', message: testName}
: {pass: 'failed', message: `${testName}; expected ${actual} to equal ${expected}.`};
},
};
}
function it(label: string, test: () => void) {
testName = label;
test();
}
| {
"end_byte": 1487,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/test.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/logger.service.ts_0_256 | // #docregion
import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class Logger {
logs: string[] = []; // capture logs for testing
log(message: string) {
this.logs.push(message);
console.log(message);
}
}
| {
"end_byte": 256,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/logger.service.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/app.component.ts_0_1788 | import {Component, Inject} from '@angular/core';
import {APP_CONFIG, AppConfig} from './injection.config';
import {UserService} from './user.service';
import {HeroesComponent} from './heroes/heroes.component';
import {HeroesTspComponent} from './heroes/heroes-tsp.component';
import {ProvidersComponent} from './providers.component';
import {CarComponent} from './car/car.component';
import {InjectorComponent} from './injector.component';
import {TestComponent} from './test.component';
import {NgIf} from '@angular/common';
@Component({
standalone: true,
selector: 'app-root',
template: `
<h1>{{title}}</h1>
<app-car></app-car>
<app-injectors></app-injectors>
<app-tests></app-tests>
<h2>User</h2>
<p id="user">
{{userInfo}}
<button type="button" (click)="nextUser()">Next User</button>
<p>
@if (isAuthorized) {
<app-heroes id="authorized"></app-heroes>
}
@if (!isAuthorized) {
<app-heroes id="unauthorized"></app-heroes>
}
@if (isAuthorized) {
<app-heroes-tsp id="tspAuthorized"></app-heroes-tsp>
}
<app-providers></app-providers>
`,
imports: [
HeroesComponent,
HeroesTspComponent,
ProvidersComponent,
CarComponent,
InjectorComponent,
TestComponent,
NgIf,
],
})
export class AppComponent {
title: string;
constructor(
@Inject(APP_CONFIG) config: AppConfig,
private userService: UserService,
) {
this.title = config.title;
}
get isAuthorized() {
return this.user.isAuthorized;
}
nextUser() {
this.userService.getNewUser();
}
get user() {
return this.userService.user;
}
get userInfo() {
return (
`Current user, ${this.user.name}, is ` + `${this.isAuthorized ? '' : 'not'} authorized. `
);
}
}
| {
"end_byte": 1788,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/app.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/user.service.ts_0_476 | // #docregion
import {Injectable} from '@angular/core';
export class User {
constructor(
public name: string,
public isAuthorized = false,
) {}
}
// TODO: get the user; don't 'new' it.
const alice = new User('Alice', true);
const bob = new User('Bob', false);
@Injectable({
providedIn: 'root',
})
export class UserService {
user = bob; // initial user is Bob
// swap users
getNewUser() {
return (this.user = this.user === bob ? alice : bob);
}
}
| {
"end_byte": 476,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/user.service.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/injection.config.ts_0_355 | import {AppConfig} from './app-config';
export {AppConfig} from './app-config';
// #docregion token
import {InjectionToken} from '@angular/core';
export const APP_CONFIG = new InjectionToken<AppConfig>('app.config');
// #enddocregion token
export const HERO_DI_CONFIG: AppConfig = {
apiEndpoint: 'api.heroes.com',
title: 'Dependency Injection',
};
| {
"end_byte": 355,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/injection.config.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/app.config.ts_0_483 | import {ApplicationConfig} from '@angular/core';
import {Logger} from './logger.service';
import {UserService} from './user.service';
import {APP_CONFIG, HERO_DI_CONFIG} from './injection.config';
import {provideProtractorTestingSupport} from '@angular/platform-browser';
const appConfig: ApplicationConfig = {
providers: [
provideProtractorTestingSupport(),
Logger,
UserService,
{provide: APP_CONFIG, useValue: HERO_DI_CONFIG},
],
};
export default appConfig;
| {
"end_byte": 483,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/app.config.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/app.component.2.ts_0_601 | import {Component, Inject} from '@angular/core';
import {APP_CONFIG, AppConfig} from './injection.config';
import {CarComponent} from './car/car.component';
import {HeroesComponent} from './heroes/heroes.component';
@Component({
standalone: true,
selector: 'app-root',
template: `
<h1>{{title}}</h1>
<app-car></app-car>
<app-heroes></app-heroes>
`,
imports: [CarComponent, HeroesComponent],
})
export class AppComponent {
title: string;
// #docregion ctor
constructor(@Inject(APP_CONFIG) config: AppConfig) {
this.title = config.title;
}
// #enddocregion ctor
}
| {
"end_byte": 601,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/app.component.2.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/injector.component.ts_0_1144 | // #docplaster
// #docregion
import {Component, Injector} from '@angular/core';
import {Car, Engine, Tires} from './car/car';
import {Hero} from './heroes/hero';
import {HeroService} from './heroes/hero.service';
import {heroServiceProvider} from './heroes/hero.service.provider';
import {Logger} from './logger.service';
@Component({
standalone: true,
selector: 'app-injectors',
template: `
<h2>Other Injections</h2>
<div id="car">{{car.drive()}}</div>
<div id="hero">{{hero.name}}</div>
<div id="rodent">{{rodent}}</div>
`,
providers: [Car, Engine, Tires, heroServiceProvider, Logger],
})
export class InjectorComponent {
car: Car;
heroService: HeroService;
hero: Hero;
constructor(private injector: Injector) {
this.car = this.injector.get(Car);
this.heroService = this.injector.get(HeroService);
this.hero = this.heroService.getHeroes()[0];
}
get rodent() {
const rousDontExist = "R.O.U.S.'s? I don't think they exist!";
return this.injector.get(ROUS, rousDontExist);
}
}
/**
* R.O.U.S. - Rodents Of Unusual Size
* // https://www.youtube.com/watch?v=BOv5ZjAOpC8
*/
class ROUS {}
| {
"end_byte": 1144,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/injector.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/providers.component.ts_0_7319 | /*
* A collection of demo components showing different ways to provide services
* in @Component metadata
*/
import {Component, Inject, Injectable, OnInit} from '@angular/core';
import {APP_CONFIG, AppConfig, HERO_DI_CONFIG} from './injection.config';
import {HeroService} from './heroes/hero.service';
import {heroServiceProvider} from './heroes/hero.service.provider';
import {Logger} from './logger.service';
import {UserService} from './user.service';
const template = '{{log}}';
@Component({
standalone: true,
selector: 'provider-1',
template,
// #docregion providers-logger
providers: [Logger],
// #enddocregion providers-logger
})
export class Provider1Component {
log: string;
constructor(logger: Logger) {
logger.log('Hello from logger provided with Logger class');
this.log = logger.logs[0];
}
}
//////////////////////////////////////////
@Component({
standalone: true,
selector: 'provider-3',
template,
providers:
// #docregion providers-3
[{provide: Logger, useClass: Logger}],
// #enddocregion providers-3
})
export class Provider3Component {
log: string;
constructor(logger: Logger) {
logger.log('Hello from logger provided with useClass:Logger');
this.log = logger.logs[0];
}
}
//////////////////////////////////////////
export class BetterLogger extends Logger {}
@Component({
standalone: true,
selector: 'provider-4',
template,
providers:
// #docregion providers-4
[{provide: Logger, useClass: BetterLogger}],
// #enddocregion providers-4
})
export class Provider4Component {
log: string;
constructor(logger: Logger) {
logger.log('Hello from logger provided with useClass:BetterLogger');
this.log = logger.logs[0];
}
}
//////////////////////////////////////////
// #docregion EvenBetterLogger
@Injectable()
export class EvenBetterLogger extends Logger {
constructor(private userService: UserService) {
super();
}
override log(message: string) {
const name = this.userService.user.name;
super.log(`Message to ${name}: ${message}`);
}
}
// #enddocregion EvenBetterLogger
@Component({
standalone: true,
selector: 'provider-5',
template,
providers:
// #docregion providers-5
[UserService, {provide: Logger, useClass: EvenBetterLogger}],
// #enddocregion providers-5
})
export class Provider5Component {
log: string;
constructor(logger: Logger) {
logger.log('Hello from EvenBetterlogger');
this.log = logger.logs[0];
}
}
//////////////////////////////////////////
export class NewLogger extends Logger {}
export class OldLogger {
logs: string[] = [];
log(message: string) {
throw new Error('Should not call the old logger!');
}
}
@Component({
standalone: true,
selector: 'provider-6a',
template,
providers: [
NewLogger,
// Not aliased! Creates two instances of `NewLogger`
{provide: OldLogger, useClass: NewLogger},
],
})
export class Provider6aComponent {
log: string;
constructor(newLogger: NewLogger, oldLogger: OldLogger) {
if (newLogger === oldLogger) {
throw new Error('expected the two loggers to be different instances');
}
oldLogger.log('Hello OldLogger (but we want NewLogger)');
// The newLogger wasn't called so no logs[]
// display the logs of the oldLogger.
this.log = newLogger.logs[0] || oldLogger.logs[0];
}
}
@Component({
standalone: true,
selector: 'provider-6b',
template,
providers:
// #docregion providers-6b
[
NewLogger,
// Alias OldLogger w/ reference to NewLogger
{provide: OldLogger, useExisting: NewLogger},
],
// #enddocregion providers-6b
})
export class Provider6bComponent {
log: string;
constructor(newLogger: NewLogger, oldLogger: OldLogger) {
if (newLogger !== oldLogger) {
throw new Error('expected the two loggers to be the same instance');
}
oldLogger.log('Hello from NewLogger (via aliased OldLogger)');
this.log = newLogger.logs[0];
}
}
//////////////////////////////////////////
// An object in the shape of the logger service
function silentLoggerFn() {}
export const SilentLogger = {
logs: ['Silent logger says "Shhhhh!". Provided via "useValue"'],
log: silentLoggerFn,
};
@Component({
standalone: true,
selector: 'provider-7',
template,
providers: [{provide: Logger, useValue: SilentLogger}],
})
export class Provider7Component {
log: string;
constructor(logger: Logger) {
logger.log('Hello from logger provided with useValue');
this.log = logger.logs[0];
}
}
/////////////////
@Component({
standalone: true,
selector: 'provider-8',
template,
providers: [heroServiceProvider, Logger, UserService],
})
export class Provider8Component {
// must be true else this component would have blown up at runtime
log = 'Hero service injected successfully via heroServiceProvider';
constructor(heroService: HeroService) {}
}
/////////////////
@Component({
standalone: true,
selector: 'provider-9',
template,
/*
// #docregion providers-9-interface
// Can't use interface as provider token
[{ provide: AppConfig, useValue: HERO_DI_CONFIG })]
// #enddocregion providers-9-interface
*/
// #docregion providers-9
providers: [{provide: APP_CONFIG, useValue: HERO_DI_CONFIG}],
// #enddocregion providers-9
})
export class Provider9Component implements OnInit {
log = '';
/*
// #docregion provider-9-ctor-interface
// Can't inject using the interface as the parameter type
constructor(private config: AppConfig){ }
// #enddocregion provider-9-ctor-interface
*/
constructor(@Inject(APP_CONFIG) private config: AppConfig) {}
ngOnInit() {
this.log = 'APP_CONFIG Application title is ' + this.config.title;
}
}
//////////////////////////////////////////
// Sample providers 1 to 7 illustrate a required logger dependency.
// Optional logger, can be null
import {Optional} from '@angular/core';
const someMessage = 'Hello from the injected logger';
@Component({
standalone: true,
selector: 'provider-10',
template,
providers: [{provide: Logger, useValue: null}],
})
export class Provider10Component implements OnInit {
log = '';
constructor(@Optional() private logger?: Logger) {
if (this.logger) {
this.logger.log(someMessage);
}
}
ngOnInit() {
this.log = this.logger ? this.logger.logs[0] : 'Optional logger was not available';
}
}
/////////////////
@Component({
standalone: true,
selector: 'app-providers',
template: `
<h2>Provider variations</h2>
<div id="p1"><provider-1></provider-1></div>
<div id="p3"><provider-3></provider-3></div>
<div id="p4"><provider-4></provider-4></div>
<div id="p5"><provider-5></provider-5></div>
<div id="p6a"><provider-6a></provider-6a></div>
<div id="p6b"><provider-6b></provider-6b></div>
<div id="p7"><provider-7></provider-7></div>
<div id="p8"><provider-8></provider-8></div>
<div id="p9"><provider-9></provider-9></div>
<div id="p10"><provider-10></provider-10></div>
`,
imports: [
Provider1Component,
Provider3Component,
Provider4Component,
Provider5Component,
Provider6aComponent,
Provider6bComponent,
Provider7Component,
Provider8Component,
Provider9Component,
Provider10Component,
],
})
export class ProvidersComponent {}
| {
"end_byte": 7319,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/providers.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/car/car.component.ts_0_980 | // #docregion
import {Component} from '@angular/core';
import {Car, Engine, Tires} from './car';
import {Car as CarNoDi} from './car-no-di';
import {CarFactory} from './car-factory';
import {testCar, simpleCar, superCar} from './car-creations';
import {useInjector} from './car-injector';
@Component({
standalone: true,
selector: 'app-car',
template: `
<h2>Cars</h2>
<div id="di">{{car.drive()}}</div>
<div id="nodi">{{noDiCar.drive()}}</div>
<div id="injector">{{injectorCar.drive()}}</div>
<div id="factory">{{factoryCar.drive()}}</div>
<div id="simple">{{simpleCar.drive()}}</div>
<div id="super">{{superCar.drive()}}</div>
<div id="test">{{testCar.drive()}}</div>
`,
providers: [Car, Engine, Tires],
})
export class CarComponent {
factoryCar = new CarFactory().createCar();
injectorCar = useInjector();
noDiCar = new CarNoDi();
simpleCar = simpleCar();
superCar = superCar();
testCar = testCar();
constructor(public car: Car) {}
}
| {
"end_byte": 980,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/car/car.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/car/car.ts_0_501 | import {Injectable} from '@angular/core';
export class Engine {
public cylinders = 4;
}
export class Tires {
public make = 'Flintstone';
public model = 'Square';
}
@Injectable()
export class Car {
public description = 'DI';
constructor(
public engine: Engine,
public tires: Tires,
) {}
// Method using the engine and tires
drive() {
return (
`${this.description} car with ` +
`${this.engine.cylinders} cylinders and ${this.tires.make} tires.`
);
}
}
| {
"end_byte": 501,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/car/car.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/car/car-injector.ts_0_830 | import {Injector} from '@angular/core';
import {Car, Engine, Tires} from './car';
import {Logger} from '../logger.service';
export function useInjector() {
let injector: Injector;
/*
// Cannot instantiate an Injector like this!
let injector = new Injector([
{ provide: Car, deps: [Engine, Tires] },
{ provide: Engine, deps: [] },
{ provide: Tires, deps: [] }
]);
*/
injector = Injector.create({
providers: [
{provide: Car, deps: [Engine, Tires]},
{provide: Engine, deps: []},
{provide: Tires, deps: []},
],
});
const car = injector.get(Car);
car.description = 'Injector';
injector = Injector.create({
providers: [{provide: Logger, deps: []}],
});
const logger = injector.get(Logger);
logger.log('Injector car.drive() said: ' + car.drive());
return car;
}
| {
"end_byte": 830,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/car/car-injector.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/car/car-no-di.ts_0_431 | // Car without DI
import {Engine, Tires} from './car';
export class Car {
public engine: Engine;
public tires: Tires;
public description = 'No DI';
constructor() {
this.engine = new Engine();
this.tires = new Tires();
}
// Method using the engine and tires
drive() {
return (
`${this.description} car with ` +
`${this.engine.cylinders} cylinders and ${this.tires.make} tires.`
);
}
}
| {
"end_byte": 431,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/car/car-no-di.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/car/car-creations.ts_0_968 | // Examples with car and engine variations
import {Car, Engine, Tires} from './car';
///////// example 1 ////////////
export function simpleCar() {
// Simple car with 4 cylinders and Flintstone tires.
const car = new Car(new Engine(), new Tires());
car.description = 'Simple';
return car;
}
///////// example 2 ////////////
class Engine2 {
constructor(public cylinders: number) {}
}
export function superCar() {
// Super car with 12 cylinders and Flintstone tires.
const bigCylinders = 12;
const car = new Car(new Engine2(bigCylinders), new Tires());
car.description = 'Super';
return car;
}
/////////// example 3 //////////
class MockEngine extends Engine {
override cylinders = 8;
}
class MockTires extends Tires {
override make = 'YokoGoodStone';
}
export function testCar() {
// Test car with 8 cylinders and YokoGoodStone tires.
const car = new Car(new MockEngine(), new MockTires());
car.description = 'Test';
return car;
}
| {
"end_byte": 968,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/car/car-creations.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/car/car-factory.ts_0_332 | // #docregion
import {Engine, Tires, Car} from './car';
// BAD pattern!
export class CarFactory {
createCar() {
const car = new Car(this.createEngine(), this.createTires());
car.description = 'Factory';
return car;
}
createEngine() {
return new Engine();
}
createTires() {
return new Tires();
}
}
| {
"end_byte": 332,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/car/car-factory.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.2.ts_0_315 | import {Injectable} from '@angular/core';
import {HEROES} from './mock-heroes';
import {Logger} from '../logger.service';
@Injectable({
providedIn: 'root',
})
export class HeroService {
constructor(private logger: Logger) {}
getHeroes() {
this.logger.log('Getting heroes ...');
return HEROES;
}
}
| {
"end_byte": 315,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.2.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.ts_0_91 | // #docregion
export interface Hero {
id: number;
name: string;
isSecret: boolean;
}
| {
"end_byte": 91,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.provider.ts_0_503 | // #docregion
import {HeroService} from './hero.service';
import {Logger} from '../logger.service';
import {UserService} from '../user.service';
// #docregion factory
const heroServiceFactory = (logger: Logger, userService: UserService) =>
new HeroService(logger, userService.user.isAuthorized);
// #enddocregion factory
// #docregion provider
export const heroServiceProvider = {
provide: HeroService,
useFactory: heroServiceFactory,
deps: [Logger, UserService],
};
// #enddocregion provider
| {
"end_byte": 503,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.provider.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.3.ts_0_291 | // #docregion
import {Injectable} from '@angular/core';
import {HEROES} from './mock-heroes';
@Injectable({
// declares that this service should be created
// by the root application injector.
providedIn: 'root',
})
export class HeroService {
getHeroes() {
return HEROES;
}
}
| {
"end_byte": 291,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.3.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero-list.component.2.ts_0_637 | // #docplaster
// #docregion
import {NgFor} from '@angular/common';
import {Component} from '@angular/core';
import {Hero} from './hero';
// #enddocregion
import {HeroService} from './hero.service.1';
/*
// #docregion
import { HeroService } from './hero.service';
// #enddocregion
*/
// #docregion
@Component({
standalone: true,
selector: 'app-hero-list',
template: `
@for (hero of heroes; track hero) {
<div>{{hero.id}} - {{hero.name}}</div>
}
`,
imports: [NgFor],
})
export class HeroListComponent {
heroes: Hero[];
constructor(heroService: HeroService) {
this.heroes = heroService.getHeroes();
}
}
| {
"end_byte": 637,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero-list.component.2.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/mock-heroes.ts_0_492 | // #docregion
import {Hero} from './hero';
export const HEROES: Hero[] = [
{id: 12, isSecret: false, name: 'Dr. Nice'},
{id: 13, isSecret: false, name: 'Bombasto'},
{id: 14, isSecret: false, name: 'Celeritas'},
{id: 15, isSecret: false, name: 'Magneta'},
{id: 16, isSecret: false, name: 'RubberMan'},
{id: 17, isSecret: false, name: 'Dynama'},
{id: 18, isSecret: true, name: 'Dr. IQ'},
{id: 19, isSecret: true, name: 'Magma'},
{id: 20, isSecret: true, name: 'Tornado'},
];
| {
"end_byte": 492,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/mock-heroes.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/dummy.module.ts_0_786 | /// Dummy modules to satisfy Angular Language Service
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
////////
import {HeroListComponent as HeroListComponent1} from './hero-list.component.1';
@NgModule({
imports: [CommonModule],
declarations: [HeroListComponent1],
exports: [HeroListComponent1],
})
export class DummyModule1 {}
/////////
import {HeroListComponent as HeroListComponent2} from './hero-list.component.2';
@NgModule({
imports: [CommonModule],
declarations: [HeroListComponent2],
})
export class DummyModule2 {}
/////////
import {HeroesComponent as HeroesComponent1} from './heroes.component.1';
@NgModule({
imports: [CommonModule, DummyModule1],
declarations: [HeroesComponent1],
})
export class DummyModule3 {}
| {
"end_byte": 786,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/dummy.module.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/heroes.component.1.ts_0_373 | import {Component} from '@angular/core';
import {HeroService} from './hero.service';
import {HeroListComponent} from './hero-list.component';
@Component({
standalone: true,
selector: 'app-heroes',
providers: [HeroService],
template: `
<h2>Heroes</h2>
<app-hero-list></app-hero-list>
`,
imports: [HeroListComponent],
})
export class HeroesComponent {}
| {
"end_byte": 373,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/heroes.component.1.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/heroes.component.ts_0_411 | // #docregion
import {Component} from '@angular/core';
import {heroServiceProvider} from './hero.service.provider';
import {HeroListComponent} from './hero-list.component';
@Component({
standalone: true,
selector: 'app-heroes',
providers: [heroServiceProvider],
template: `
<h2>Heroes</h2>
<app-hero-list></app-hero-list>
`,
imports: [HeroListComponent],
})
export class HeroesComponent {}
| {
"end_byte": 411,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/heroes.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/heroes-tsp.component.ts_0_516 | import {Component} from '@angular/core';
import {HeroListComponent} from './hero-list.component';
/**
* A version of `HeroesComponent` that does not provide the `HeroService` (and thus relies on its
* `Injectable`-declared provider) in order to function.
*
* TSP stands for Tree-Shakeable Provider.
*/
@Component({
standalone: true,
selector: 'app-heroes-tsp',
template: `
<h2>Heroes</h2>
<app-hero-list></app-hero-list>
`,
imports: [HeroListComponent],
})
export class HeroesTspComponent {}
| {
"end_byte": 516,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/heroes-tsp.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.0.ts_0_110 | import {Injectable} from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class HeroService {}
| {
"end_byte": 110,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.0.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero-list.component.1.ts_0_368 | import {NgFor} from '@angular/common';
import {Component} from '@angular/core';
import {HEROES} from './mock-heroes';
@Component({
standalone: true,
selector: 'app-hero-list',
template: `
@for (hero of heroes; track hero) {
<div>{{hero.id}} - {{hero.name}}</div>
}
`,
imports: [NgFor],
})
export class HeroListComponent {
heroes = HEROES;
}
| {
"end_byte": 368,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero-list.component.1.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.ts_0_760 | // #docregion
import {Injectable} from '@angular/core';
import {HEROES} from './mock-heroes';
import {Logger} from '../logger.service';
import {UserService} from '../user.service';
@Injectable({
providedIn: 'root',
useFactory: (logger: Logger, userService: UserService) =>
new HeroService(logger, userService.user.isAuthorized),
deps: [Logger, UserService],
})
export class HeroService {
// #docregion internals
constructor(
private logger: Logger,
private isAuthorized: boolean,
) {}
getHeroes() {
const auth = this.isAuthorized ? 'authorized' : 'unauthorized';
this.logger.log(`Getting heroes for ${auth} user.`);
return HEROES.filter((hero) => this.isAuthorized || !hero.isSecret);
}
// #enddocregion internals
}
| {
"end_byte": 760,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.5.ts_0_525 | // #docregion
import {EnvironmentInjector, inject, Injectable, runInInjectionContext} from '@angular/core';
@Injectable({providedIn: 'root'})
export class SomeService {}
// #docregion run-in-context
@Injectable({
providedIn: 'root',
})
export class HeroService {
private environmentInjector = inject(EnvironmentInjector);
someMethod() {
runInInjectionContext(this.environmentInjector, () => {
inject(SomeService); // Do what you need with the injected service
});
}
}
// #enddocregion run-in-context
| {
"end_byte": 525,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.5.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero-list.component.ts_0_644 | // #docregion
import {Component} from '@angular/core';
import {Hero} from './hero';
import {HeroService} from './hero.service';
import {NgFor} from '@angular/common';
@Component({
standalone: true,
selector: 'app-hero-list',
template: `
@for (hero of heroes; track hero) {
<div>
{{hero.id}} - {{hero.name}}
({{hero.isSecret ? 'secret' : 'public'}})
</div>
}
`,
imports: [NgFor],
})
export class HeroListComponent {
heroes: Hero[];
// #docregion ctor-signature
constructor(
heroService: HeroService, // #enddocregion ctor-signature
) {
this.heroes = heroService.getHeroes();
}
}
| {
"end_byte": 644,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero-list.component.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.1.ts_0_202 | // #docregion
import {Injectable} from '@angular/core';
import {HEROES} from './mock-heroes';
@Injectable({
providedIn: 'root',
})
export class HeroService {
getHeroes() {
return HEROES;
}
}
| {
"end_byte": 202,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/heroes/hero.service.1.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/tree-shaking/app.module.ts_0_320 | import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RouterModule} from '@angular/router';
import {ServiceModule} from './service-and-module';
// #docregion
@NgModule({
imports: [BrowserModule, RouterModule.forRoot([]), ServiceModule],
})
export class AppModule {}
| {
"end_byte": 320,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/tree-shaking/app.module.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/tree-shaking/service.0.ts_0_206 | import {Injectable} from '@angular/core';
// #docregion
@Injectable({
providedIn: 'root',
useFactory: () => new Service('dependency'),
})
export class Service {
constructor(private dep: string) {}
}
| {
"end_byte": 206,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/tree-shaking/service.0.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/tree-shaking/service.ts_0_120 | import {Injectable} from '@angular/core';
// #docregion
@Injectable({
providedIn: 'root',
})
export class Service {}
| {
"end_byte": 120,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/tree-shaking/service.ts"
} |
angular/adev/src/content/examples/dependency-injection/src/app/tree-shaking/service-and-module.ts_0_201 | // #docregion
import {Injectable, NgModule} from '@angular/core';
@Injectable()
export class Service {
doSomething(): void {}
}
@NgModule({
providers: [Service],
})
export class ServiceModule {}
| {
"end_byte": 201,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/dependency-injection/src/app/tree-shaking/service-and-module.ts"
} |
angular/adev/src/content/examples/animations/BUILD.bazel_0_1029 | package(default_visibility = ["//visibility:public"])
exports_files([
"src/app/animations.1.ts",
"src/app/animations.ts",
"src/app/app.component.html",
"src/app/app.component.ts",
"src/app/app.module.1.ts",
"src/app/app.routes.ts",
"src/app/hero-list-auto.component.ts",
"src/app/hero-list-enter-leave.component.ts",
"src/app/hero-list-groups.component.ts",
"src/app/hero-list-page.component.html",
"src/app/hero-list-page.component.ts",
"src/app/insert-remove.component.html",
"src/app/insert-remove.component.ts",
"src/app/open-close.component.1.html",
"src/app/open-close.component.1.ts",
"src/app/open-close.component.2.html",
"src/app/open-close.component.2.ts",
"src/app/open-close.component.3.html",
"src/app/open-close.component.3.ts",
"src/app/open-close.component.4.html",
"src/app/open-close.component.4.ts",
"src/app/open-close.component.css",
"src/app/open-close.component.ts",
"src/app/status-slider.component.ts",
])
| {
"end_byte": 1029,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/BUILD.bazel"
} |
angular/adev/src/content/examples/animations/e2e/src/enter-leave.po.ts_0_454 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-hero-list-enter-leave-page');
}
export function getComponent() {
return by.css('app-hero-list-enter-leave');
}
export function getComponentContainer() {
const findContainer = () => by.css('ul');
return locate(getComponent(), findContainer());
}
export function getHeroesList() {
return getComponentContainer().all(by.css('li'));
}
| {
"end_byte": 454,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/enter-leave.po.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/app.e2e-spec.ts_0_8690 | import {browser} from 'protractor';
import {logging} from 'selenium-webdriver';
import * as openClose from './open-close.po';
import * as statusSlider from './status-slider.po';
import * as toggle from './toggle.po';
import * as enterLeave from './enter-leave.po';
import * as auto from './auto.po';
import * as filterStagger from './filter-stagger.po';
import * as heroGroups from './hero-groups';
import {getLinkById, sleepFor} from './util';
import {getComponentSection, getToggleButton} from './querying.po';
describe('Animation Tests', () => {
const routingAnimationDuration = 350;
const openCloseHref = getLinkById('open-close');
const statusSliderHref = getLinkById('status');
const toggleHref = getLinkById('toggle');
const enterLeaveHref = getLinkById('enter-leave');
const autoHref = getLinkById('auto');
const filterHref = getLinkById('heroes');
const heroGroupsHref = getLinkById('hero-groups');
const queryingHref = getLinkById('querying');
const newPageSleepFor = (ms = 0) => sleepFor(ms + routingAnimationDuration);
beforeAll(() => browser.get(''));
describe('Open/Close Component', () => {
const closedHeight = '100px';
const openHeight = '200px';
beforeAll(async () => {
await openCloseHref.click();
await newPageSleepFor(300);
});
it('should be open', async () => {
const toggleButton = openClose.getToggleButton();
const container = openClose.getComponentContainer();
let text = await container.getText();
if (text.includes('Closed')) {
await toggleButton.click();
await browser.wait(
async () => (await container.getCssValue('height')) === openHeight,
2000,
);
}
text = await container.getText();
const containerHeight = await container.getCssValue('height');
expect(text).toContain('The box is now Open!');
expect(containerHeight).toBe(openHeight);
});
it('should be closed', async () => {
const toggleButton = openClose.getToggleButton();
const container = openClose.getComponentContainer();
let text = await container.getText();
if (text.includes('Open')) {
await toggleButton.click();
await browser.wait(
async () => (await container.getCssValue('height')) === closedHeight,
2000,
);
}
text = await container.getText();
const containerHeight = await container.getCssValue('height');
expect(text).toContain('The box is now Closed!');
expect(containerHeight).toBe(closedHeight);
});
it('should log animation events', async () => {
const toggleButton = openClose.getToggleButton();
const loggingCheckbox = openClose.getLoggingCheckbox();
await loggingCheckbox.click();
await toggleButton.click();
const logs = await browser.manage().logs().get(logging.Type.BROWSER);
const animationMessages = logs.filter(({message}) => message.includes('Animation'));
expect(animationMessages.length).toBeGreaterThan(0);
});
});
describe('Status Slider Component', () => {
const activeColor = 'rgba(117, 70, 0, 1)';
const inactiveColor = 'rgba(0, 0, 255, 1)';
beforeAll(async () => {
await statusSliderHref.click();
await newPageSleepFor(2000);
});
it('should be inactive with a blue background', async () => {
const toggleButton = statusSlider.getToggleButton();
const container = statusSlider.getComponentContainer();
let text = await container.getText();
if (text === 'Active') {
await toggleButton.click();
await browser.wait(
async () => (await container.getCssValue('backgroundColor')) === inactiveColor,
3000,
);
}
text = await container.getText();
const bgColor = await container.getCssValue('backgroundColor');
expect(text).toBe('Inactive');
expect(bgColor).toBe(inactiveColor);
});
it('should be active with an orange background', async () => {
const toggleButton = statusSlider.getToggleButton();
const container = statusSlider.getComponentContainer();
let text = await container.getText();
if (text === 'Inactive') {
await toggleButton.click();
await browser.wait(
async () => (await container.getCssValue('backgroundColor')) === activeColor,
3000,
);
}
text = await container.getText();
const bgColor = await container.getCssValue('backgroundColor');
expect(text).toBe('Active');
expect(bgColor).toBe(activeColor);
});
});
describe('Toggle Animations Component', () => {
beforeAll(async () => {
await toggleHref.click();
await newPageSleepFor();
});
it('should disabled animations on the child element', async () => {
const toggleButton = toggle.getToggleAnimationsButton();
await toggleButton.click();
const container = toggle.getComponentContainer();
const cssClasses = await container.getAttribute('class');
expect(cssClasses).toContain('ng-animate-disabled');
});
});
describe('Enter/Leave Component', () => {
beforeAll(async () => {
await enterLeaveHref.click();
await newPageSleepFor(100);
});
it('should attach a flyInOut trigger to the list of items', async () => {
const heroesList = enterLeave.getHeroesList();
const hero = heroesList.get(0);
const cssClasses = await hero.getAttribute('class');
const transform = await hero.getCssValue('transform');
expect(cssClasses).toContain('ng-trigger-flyInOut');
expect(transform).toBe('matrix(1, 0, 0, 1, 0, 0)');
});
it('should remove the hero from the list when clicked', async () => {
const heroesList = enterLeave.getHeroesList();
const total = await heroesList.count();
const hero = heroesList.get(0);
await hero.click();
await browser.wait(async () => (await heroesList.count()) < total, 2000);
});
});
describe('Auto Calculation Component', () => {
beforeAll(async () => {
await autoHref.click();
await newPageSleepFor();
});
it('should attach a shrinkOut trigger to the list of items', async () => {
const heroesList = auto.getHeroesList();
const hero = heroesList.get(0);
const cssClasses = await hero.getAttribute('class');
expect(cssClasses).toContain('ng-trigger-shrinkOut');
});
it('should remove the hero from the list when clicked', async () => {
const heroesList = auto.getHeroesList();
const total = await heroesList.count();
const hero = heroesList.get(0);
await hero.click();
await browser.wait(async () => (await heroesList.count()) < total, 2000);
});
});
describe('Filter/Stagger Component', () => {
beforeAll(async () => {
await filterHref.click();
await newPageSleepFor();
});
it('should attach a filterAnimations trigger to the list container', async () => {
const heroesList = filterStagger.getComponentContainer();
const cssClasses = await heroesList.getAttribute('class');
expect(cssClasses).toContain('ng-trigger-filterAnimation');
});
it('should filter down the list when a search is performed', async () => {
const heroesList = filterStagger.getHeroesList();
const total = await heroesList.count();
const input = filterStagger.getInput();
await input.sendKeys('Mag');
await browser.wait(async () => (await heroesList.count()) === 2, 2000);
const newTotal = await heroesList.count();
expect(newTotal).toBeLessThan(total);
});
});
describe('Hero Groups Component', () => {
beforeAll(async () => {
await heroGroupsHref.click();
await newPageSleepFor(400);
});
it('should attach a flyInOut trigger to the list of items', async () => {
const heroesList = heroGroups.getHeroesList();
const hero = heroesList.get(0);
const cssClasses = await hero.getAttribute('class');
const transform = await hero.getCssValue('transform');
const opacity = await hero.getCssValue('opacity');
expect(cssClasses).toContain('ng-trigger-flyInOut');
expect(transform).toBe('matrix(1, 0, 0, 1, 0, 0)');
expect(opacity).toBe('1');
});
it('should remove the hero from the list when clicked', async () => {
const heroesList = heroGroups.getHeroesList();
const total = await heroesList.count();
const hero = heroesList.get(0);
await hero.click();
await browser.wait(async () => (await heroesList.count()) < total, 2000);
});
}); | {
"end_byte": 8690,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/app.e2e-spec.ts_8694_10148 | describe('Querying Component', () => {
const queryingAnimationDuration = 2500;
beforeAll(async () => {
await queryingHref.click();
await newPageSleepFor(queryingAnimationDuration);
});
it('should toggle the section', async () => {
const toggleButton = getToggleButton();
const section = getComponentSection();
expect(await section.isPresent()).toBe(true);
// toggling off
await toggleButton.click();
await newPageSleepFor(queryingAnimationDuration);
expect(await section.isPresent()).toBe(false);
// toggling on
await toggleButton.click();
await newPageSleepFor(queryingAnimationDuration);
expect(await section.isPresent()).toBe(true);
await newPageSleepFor(queryingAnimationDuration);
});
it(`should disable the button for the animation's duration`, async () => {
const toggleButton = getToggleButton();
expect(await toggleButton.isEnabled()).toBe(true);
// toggling off
await toggleButton.click();
expect(await toggleButton.isEnabled()).toBe(false);
await newPageSleepFor(queryingAnimationDuration);
expect(await toggleButton.isEnabled()).toBe(true);
// toggling on
await toggleButton.click();
expect(await toggleButton.isEnabled()).toBe(false);
await newPageSleepFor(queryingAnimationDuration);
expect(await toggleButton.isEnabled()).toBe(true);
});
});
}); | {
"end_byte": 10148,
"start_byte": 8694,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/app.e2e-spec.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/filter-stagger.po.ts_0_463 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-hero-list-page');
}
export function getComponentContainer() {
const findContainer = () => by.css('ul');
return locate(getPage(), findContainer());
}
export function getHeroesList() {
return getComponentContainer().all(by.css('li'));
}
export function getInput() {
const input = () => by.css('input');
return locate(getPage(), input());
}
| {
"end_byte": 463,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/filter-stagger.po.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/toggle.po.ts_0_712 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-toggle-animations-child-page');
}
export function getComponent() {
return by.css('app-open-close-toggle');
}
export function getToggleButton() {
const toggleButton = () => by.buttonText('Toggle Open/Closed');
return locate(getComponent(), toggleButton());
}
export function getToggleAnimationsButton() {
const toggleAnimationsButton = () => by.buttonText('Toggle Animations');
return locate(getComponent(), toggleAnimationsButton());
}
export function getComponentContainer() {
const findContainer = () => by.css('div');
return locate(getComponent()).all(findContainer()).get(0);
}
| {
"end_byte": 712,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/toggle.po.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/status-slider.po.ts_0_499 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-status-slider-page');
}
export function getComponent() {
return by.css('app-status-slider');
}
export function getToggleButton() {
const toggleButton = () => by.buttonText('Toggle Status');
return locate(getComponent(), toggleButton());
}
export function getComponentContainer() {
const findContainer = () => by.css('div');
return locate(getComponent(), findContainer());
}
| {
"end_byte": 499,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/status-slider.po.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/hero-groups.ts_0_444 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-hero-list-groups-page');
}
export function getComponent() {
return by.css('app-hero-list-groups');
}
export function getComponentContainer() {
const findContainer = () => by.css('ul');
return locate(getComponent(), findContainer());
}
export function getHeroesList() {
return getComponentContainer().all(by.css('li'));
}
| {
"end_byte": 444,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/hero-groups.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/querying.po.ts_0_410 | import {by} from 'protractor';
import {locate} from './util';
export function getComponent() {
return by.css('app-querying');
}
export function getToggleButton() {
const toggleButton = () => by.className('toggle');
return locate(getComponent(), toggleButton());
}
export function getComponentSection() {
const findSection = () => by.css('section');
return locate(getComponent(), findSection());
}
| {
"end_byte": 410,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/querying.po.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/open-close.po.ts_0_662 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-open-close-page');
}
export function getComponent() {
return by.css('app-open-close');
}
export function getToggleButton() {
const toggleButton = () => by.buttonText('Toggle Open/Close');
return locate(getComponent(), toggleButton());
}
export function getLoggingCheckbox() {
const loggingCheckbox = () => by.css('section > input[type="checkbox"]');
return locate(getPage(), loggingCheckbox());
}
export function getComponentContainer() {
const findContainer = () => by.css('div');
return locate(getComponent(), findContainer());
}
| {
"end_byte": 662,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/open-close.po.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/util.ts_0_548 | import {Locator, ElementFinder, browser, by, element} from 'protractor';
/**
*
* locate(finder1, finder2) => element(finder1).element(finder2).element(finderN);
*/
export function locate(locator: Locator, ...locators: Locator[]) {
return locators.reduce(
(current: ElementFinder, next: Locator) => current.element(next),
element(locator),
) as ElementFinder;
}
export async function sleepFor(time = 1000) {
return await browser.sleep(time);
}
export function getLinkById(id: string) {
return element(by.css(`a[id=${id}]`));
}
| {
"end_byte": 548,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/util.ts"
} |
angular/adev/src/content/examples/animations/e2e/src/auto.po.ts_0_440 | import {by} from 'protractor';
import {locate} from './util';
export function getPage() {
return by.css('app-hero-list-auto-page');
}
export function getComponent() {
return by.css('app-hero-list-auto');
}
export function getComponentContainer() {
const findContainer = () => by.css('ul');
return locate(getComponent(), findContainer());
}
export function getHeroesList() {
return getComponentContainer().all(by.css('li'));
}
| {
"end_byte": 440,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/e2e/src/auto.po.ts"
} |
angular/adev/src/content/examples/animations/src/index.html_0_256 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Animations</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<app-root></app-root>
</body>
</html>
| {
"end_byte": 256,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/index.html"
} |
angular/adev/src/content/examples/animations/src/main.ts_0_206 | import {bootstrapApplication} from '@angular/platform-browser';
import {AppComponent} from './app/app.component';
import {appConfig} from './app/app.config';
bootstrapApplication(AppComponent, appConfig);
| {
"end_byte": 206,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/main.ts"
} |
angular/adev/src/content/examples/animations/src/app/app.component.html_0_1643 | <h1>Animations</h1>
<input type="checkbox"
id="animation-toggle"
[checked]="!animationsDisabled"
(click)="toggleAnimations()">
<label for="animation-toggle">Toggle All Animations</label>
<nav>
<a id="home" routerLink="/home" routerLinkActive="active" ariaCurrentWhenActive="page">Home</a>
<a id="about" routerLink="/about" routerLinkActive="active" ariaCurrentWhenActive="page">About</a>
<a id="open-close" routerLink="/open-close" routerLinkActive="active" ariaCurrentWhenActive="page">Open/Close</a>
<a id="status" routerLink="/status" routerLinkActive="active" ariaCurrentWhenActive="page">Status Slider</a>
<a id="toggle" routerLink="/toggle" routerLinkActive="active" ariaCurrentWhenActive="page">Toggle Animations</a>
<a id="enter-leave" routerLink="/enter-leave" routerLinkActive="active" ariaCurrentWhenActive="page">Enter/Leave</a>
<a id="auto" routerLink="/auto" routerLinkActive="active" ariaCurrentWhenActive="page">Auto Calculation</a>
<a id="heroes" routerLink="/heroes" routerLinkActive="active" ariaCurrentWhenActive="page">Filter/Stagger</a>
<a id="hero-groups" routerLink="/hero-groups" routerLinkActive="active" ariaCurrentWhenActive="page">Hero Groups</a>
<a id="insert-remove" routerLink="/insert-remove" routerLinkActive="active" ariaCurrentWhenActive="page">Insert/Remove</a>
<a id="querying" routerLink="/querying" routerLinkActive="active" ariaCurrentWhenActive="page">Querying</a>
</nav>
<!-- #docregion route-animations-outlet -->
<div [@routeAnimations]="getRouteAnimationData()">
<router-outlet></router-outlet>
</div>
<!-- #enddocregion route-animations-outlet -->
| {
"end_byte": 1643,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/app.component.html"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.3.html_0_478 | <!-- #docplaster -->
<nav>
<button type="button" (click)="toggle()">Toggle Open/Close</button>
</nav>
<!-- #docregion callbacks -->
<div [@openClose]="isOpen ? 'open' : 'closed'"
(@openClose.start)="onAnimationEvent($event)"
(@openClose.done)="onAnimationEvent($event)"
class="open-close-container">
<!-- #enddocregion callbacks -->
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
<!-- #docregion callbacks -->
</div>
<!-- #enddocregion callbacks -->
| {
"end_byte": 478,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.3.html"
} |
angular/adev/src/content/examples/animations/src/app/status-slider.component.ts_0_1711 | import {Component} from '@angular/core';
import {trigger, transition, state, animate, style, keyframes} from '@angular/animations';
@Component({
standalone: true,
selector: 'app-status-slider',
templateUrl: 'status-slider.component.html',
styleUrls: ['status-slider.component.css'],
animations: [
trigger('slideStatus', [
state('inactive', style({backgroundColor: 'blue'})),
state('active', style({backgroundColor: '#754600'})),
// #docregion keyframesWithOffsets
transition('* => active', [
animate(
'2s',
keyframes([
style({backgroundColor: 'blue', offset: 0}),
style({backgroundColor: 'red', offset: 0.8}),
style({backgroundColor: '#754600', offset: 1.0}),
]),
),
]),
transition('* => inactive', [
animate(
'2s',
keyframes([
style({backgroundColor: '#754600', offset: 0}),
style({backgroundColor: 'red', offset: 0.2}),
style({backgroundColor: 'blue', offset: 1.0}),
]),
),
]),
// #enddocregion keyframesWithOffsets
// #docregion keyframes
transition('* => active', [
animate(
'2s',
keyframes([
style({backgroundColor: 'blue'}),
style({backgroundColor: 'red'}),
style({backgroundColor: 'orange'}),
]),
),
// #enddocregion keyframes
]),
]),
],
})
export class StatusSliderComponent {
status: 'active' | 'inactive' = 'inactive';
toggle() {
if (this.status === 'active') {
this.status = 'inactive';
} else {
this.status = 'active';
}
}
}
| {
"end_byte": 1711,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/status-slider.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-groups.component.ts_0_1941 | import {Component, Input, Output, EventEmitter} from '@angular/core';
import {trigger, state, style, animate, transition, group} from '@angular/animations';
import {Hero} from './hero';
import {NgFor} from '@angular/common';
@Component({
standalone: true,
selector: 'app-hero-list-groups',
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({
width: '*',
transform: 'translateX(0)',
opacity: 1,
}),
),
transition(':enter', [
style({width: 10, transform: 'translateX(50px)', opacity: 0}),
group([
animate(
'0.3s 0.1s ease',
style({
transform: 'translateX(0)',
width: '*',
}),
),
animate(
'0.3s ease',
style({
opacity: 1,
}),
),
]),
]),
transition(':leave', [
group([
animate(
'0.3s ease',
style({
transform: 'translateX(50px)',
width: 10,
}),
),
animate(
'0.3s 0.2s ease',
style({
opacity: 0,
}),
),
]),
]),
]),
],
// #enddocregion animationdef
})
export class HeroListGroupsComponent {
@Input() heroes: Hero[] = [];
@Output() remove = new EventEmitter<number>();
removeHero(id: number) {
this.remove.emit(id);
}
}
| {
"end_byte": 1941,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-groups.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero.ts_0_56 | export interface Hero {
id: number;
name: string;
}
| {
"end_byte": 56,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero.ts"
} |
angular/adev/src/content/examples/animations/src/app/status-slider-page.component.ts_0_382 | import {Component} from '@angular/core';
import {StatusSliderComponent} from './status-slider.component';
@Component({
standalone: true,
selector: 'app-status-slider-page',
template: `
<section>
<h2>Status Slider</h2>
<app-status-slider></app-status-slider>
</section>
`,
imports: [StatusSliderComponent],
})
export class StatusSliderPageComponent {}
| {
"end_byte": 382,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/status-slider-page.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/about.component.html_0_127 | <p>
Angular's animations library makes it easy to define and apply animation effects such as page and list transitions.
</p>
| {
"end_byte": 127,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/about.component.html"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-auto.component.ts_0_827 | 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-auto',
templateUrl: 'hero-list-auto.component.html',
styleUrls: ['./hero-list-page.component.css'],
imports: [NgFor],
// #docregion auto-calc
animations: [
trigger('shrinkOut', [
state('in', style({height: '*'})),
transition('* => void', [style({height: '*'}), animate(250, style({height: 0}))]),
]),
],
// #enddocregion auto-calc
})
export class HeroListAutoComponent {
@Input() heroes: Hero[] = [];
@Output() remove = new EventEmitter<number>();
removeHero(id: number) {
this.remove.emit(id);
}
}
| {
"end_byte": 827,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-auto.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.css_0_212 | :host {
display: block;
margin-top: 1rem;
}
.open-close-container {
border: 1px solid #dddddd;
margin-top: 1em;
padding: 20px 20px 0px 20px;
color: #000000;
font-weight: bold;
font-size: 20px;
}
| {
"end_byte": 212,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.css"
} |
angular/adev/src/content/examples/animations/src/app/mock-heroes.ts_0_342 | // #docregion
import {Hero} from './hero';
export const HEROES: Hero[] = [
{id: 12, name: 'Dr. Nice'},
{id: 13, name: 'Bombasto'},
{id: 14, name: 'Celeritas'},
{id: 15, name: 'Magneta'},
{id: 16, name: 'RubberMan'},
{id: 17, name: 'Dynama'},
{id: 18, name: 'Dr. IQ'},
{id: 19, name: 'Magma'},
{id: 20, name: 'Tornado'},
];
| {
"end_byte": 342,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/mock-heroes.ts"
} |
angular/adev/src/content/examples/animations/src/app/home.component.ts_0_211 | import {Component} from '@angular/core';
@Component({
standalone: true,
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
})
export class HomeComponent {}
| {
"end_byte": 211,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/home.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.2.html_0_395 | <!-- #docplaster -->
<nav>
<button type="button" (click)="toggle()">Toggle Boolean/Close</button>
</nav>
<!-- #docregion trigger-boolean -->
<div [@openClose]="isOpen ? true : false" class="open-close-container">
<!-- #enddocregion trigger-boolean -->
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
<!-- #docregion trigger-boolean -->
</div>
<!-- #enddocregion trigger-boolean -->
| {
"end_byte": 395,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.2.html"
} |
angular/adev/src/content/examples/animations/src/app/app.routes.ts_0_2155 | import {Routes} from '@angular/router';
import {OpenClosePageComponent} from './open-close-page.component';
import {StatusSliderPageComponent} from './status-slider-page.component';
import {ToggleAnimationsPageComponent} from './toggle-animations-page.component';
import {HeroListPageComponent} from './hero-list-page.component';
import {HeroListGroupPageComponent} from './hero-list-group-page.component';
import {HeroListEnterLeavePageComponent} from './hero-list-enter-leave-page.component';
import {HeroListAutoCalcPageComponent} from './hero-list-auto-page.component';
import {InsertRemoveComponent} from './insert-remove.component';
import {QueryingComponent} from './querying.component';
import {HomeComponent} from './home.component';
import {AboutComponent} from './about.component';
// #docregion route-animation-data
export const routes: Routes = [
{path: '', pathMatch: 'full', redirectTo: '/enter-leave'},
{
path: 'open-close',
component: OpenClosePageComponent,
data: {animation: 'openClosePage'},
},
{
path: 'status',
component: StatusSliderPageComponent,
data: {animation: 'statusPage'},
},
{
path: 'toggle',
component: ToggleAnimationsPageComponent,
data: {animation: 'togglePage'},
},
{
path: 'heroes',
component: HeroListPageComponent,
data: {animation: 'filterPage'},
},
{
path: 'hero-groups',
component: HeroListGroupPageComponent,
data: {animation: 'heroGroupPage'},
},
{
path: 'enter-leave',
component: HeroListEnterLeavePageComponent,
data: {animation: 'enterLeavePage'},
},
{
path: 'auto',
component: HeroListAutoCalcPageComponent,
data: {animation: 'autoPage'},
},
{
path: 'insert-remove',
component: InsertRemoveComponent,
data: {animation: 'insertRemovePage'},
},
{
path: 'querying',
component: QueryingComponent,
data: {animation: 'queryingPage'},
},
{
path: 'home',
component: HomeComponent,
data: {animation: 'HomePage'},
},
{
path: 'about',
component: AboutComponent,
data: {animation: 'AboutPage'},
},
];
// #enddocregion route-animation-data
| {
"end_byte": 2155,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/app.routes.ts"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.3.ts_0_944 | // #docplaster
// #docregion reusable
import {Component, Input} from '@angular/core';
import {transition, trigger, useAnimation, AnimationEvent} from '@angular/animations';
import {transitionAnimation} from './animations';
@Component({
standalone: true,
selector: 'app-open-close-reusable',
animations: [
trigger('openClose', [
transition('open => closed', [
useAnimation(transitionAnimation, {
params: {
height: 0,
opacity: 1,
backgroundColor: 'red',
time: '1s',
},
}),
]),
]),
],
templateUrl: 'open-close.component.html',
styleUrls: ['open-close.component.css'],
})
// #enddocregion reusable
export class OpenCloseBooleanComponent {
isOpen = false;
toggle() {
this.isOpen = !this.isOpen;
}
@Input() logging = false;
onAnimationEvent(event: AnimationEvent) {
if (!this.logging) {
return;
}
}
}
| {
"end_byte": 944,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.3.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-page.component.css_0_1204 | .heroes {
margin: 0 0 2em 0;
list-style-type: none;
padding: 0;
width: 15em;
}
.heroes li {
display: flex;
align-items: center;
width: 100%;
overflow: hidden;
}
.heroes .inner {
flex: 1;
background-color: #EEE;
margin: .5em;
padding: 0;
border-radius: 4px;
display: flex;
align-items: stretch;
}
.heroes button.inner {
cursor: pointer;
font-size: inherit;
}
.heroes button.inner:hover {
color: #2c3a41;
background-color: #e6e6e6;
left: .1em;
}
.heroes button.inner:active {
background-color: #525252;
color: #fafafa;
}
.heroes button.inner.selected {
background-color: black;
color: white;
}
.heroes button.inner.selected:hover {
background-color: #505050;
color: white;
}
.heroes button.inner.selected:active {
background-color: black;
color: white;
}
.heroes .badge {
display: inline-block;
font-size: small;
color: white;
padding: 0.8em 0.7em 0 0.7em;
background-color: #405061;
line-height: 1em;
margin-right: .8em;
border-radius: 4px 0 0 4px;
}
.heroes .name {
min-width: max-content;
padding: 0.5rem 0;
}
label {
display: block;
padding-bottom: .5rem;
}
input {
font-size: 100%;
margin-bottom: 1rem;
}
| {
"end_byte": 1204,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-page.component.css"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-auto-page.component.ts_0_605 | import {Component} from '@angular/core';
import {HEROES} from './mock-heroes';
import {HeroListAutoComponent} from './hero-list-auto.component';
@Component({
standalone: true,
selector: 'app-hero-list-auto-page',
template: `
<section>
<h2>Automatic Calculation</h2>
<app-hero-list-auto [heroes]="heroes" (remove)="onRemove($event)"></app-hero-list-auto>
</section>
`,
imports: [HeroListAutoComponent],
})
export class HeroListAutoCalcPageComponent {
heroes = HEROES.slice();
onRemove(id: number) {
this.heroes = this.heroes.filter((hero) => hero.id !== id);
}
}
| {
"end_byte": 605,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-auto-page.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/hero-list.component.css_0_410 | ul {
list-style-type: none;
padding: 0;
}
li {
display: block;
width: 120px;
line-height: 50px;
padding: 0 10px;
box-sizing: border-box;
background-color: #eee;
border-radius: 4px;
margin: 10px;
cursor: pointer;
overflow: hidden;
white-space: nowrap;
}
.active {
background-color: #cfd8dc;
transform: scale(1.1);
}
.inactive {
background-color: #eee;
transform: scale(1);
}
| {
"end_byte": 410,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list.component.css"
} |
angular/adev/src/content/examples/animations/src/app/hero-list-page.component.html_0_566 | <!-- #docplaster -->
<h2>Filter/Stagger</h2>
<!-- #docregion filter-animations -->
<label for="search">Search heroes: </label>
<input type="text" id="search" #criteria
(input)="updateCriteria(criteria.value)"
placeholder="Search heroes">
<ul class="heroes" [@filterAnimation]="heroesTotal">
@for (hero of heroes; track hero) {
<li class="hero">
<div class="inner">
<span class="badge">{{ hero.id }}</span>
<span class="name">{{ hero.name }}</span>
</div>
</li>
}
</ul>
<!-- #enddocregion filter-animations -->
| {
"end_byte": 566,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/hero-list-page.component.html"
} |
angular/adev/src/content/examples/animations/src/app/querying.component.ts_0_2721 | import {Component} from '@angular/core';
import {
trigger,
style,
animate,
transition,
group,
query,
animateChild,
keyframes,
} from '@angular/animations';
import {HEROES} from './mock-heroes';
import {NgIf} from '@angular/common';
@Component({
standalone: true,
selector: 'app-querying',
template: `
<nav>
<button class="toggle" (click)="show = !show" [disabled]="toggleDisabled">Toggle View</button>
</nav>
@if (show) {
<section @query (@query.start)="toggleDisabled = true" (@query.done)="toggleDisabled = false">
<p>I am a simple child element</p>
@if (show) {
<p>I am a child element that enters and leaves with its parent</p>
}
<p @animateMe>I am a child element with an animation trigger</p>
<div class="hero">
<span class="badge">{{ hero.id }}</span>
<span class="name">{{ hero.name }} <small>(heroes are always animated!)</small></span>
</div>
</section>
}
`,
styleUrls: ['./querying.component.css'],
imports: [NgIf],
animations: [
trigger('query', [
transition(':enter', [
style({height: 0}),
group([
animate(500, style({height: '*'})),
query(':enter', [
style({opacity: 0, transform: 'scale(0)'}),
animate(2000, style({opacity: 1, transform: 'scale(1)'})),
]),
query('.hero', [
style({transform: 'translateX(-100%)'}),
animate('.7s 500ms ease-in', style({transform: 'translateX(0)'})),
]),
]),
query('@animateMe', animateChild()),
]),
transition(':leave', [
style({height: '*'}),
query('@animateMe', animateChild()),
group([
animate('500ms 500ms', style({height: '0', padding: '0'})),
query(':leave', [
style({opacity: 1, transform: 'scale(1)'}),
animate('1s', style({opacity: 0, transform: 'scale(0)'})),
]),
query('.hero', [
style({transform: 'translateX(0)'}),
animate('.7s ease-out', style({transform: 'translateX(-100%)'})),
]),
]),
]),
]),
trigger('animateMe', [
transition(
'* <=> *',
animate(
'500ms cubic-bezier(.68,-0.73,.26,1.65)',
keyframes([
style({backgroundColor: 'transparent', color: '*', offset: 0}),
style({backgroundColor: 'blue', color: 'white', offset: 0.2}),
style({backgroundColor: 'transparent', color: '*', offset: 1}),
]),
),
),
]),
],
})
export class QueryingComponent {
toggleDisabled = false;
show = true;
hero = HEROES[0];
}
| {
"end_byte": 2721,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/querying.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/status-slider.component.html_0_180 | <nav>
<button type="button" (click)="toggle()">Toggle Status</button>
</nav>
<div [@slideStatus]="status" class="box">
{{ status == 'active' ? 'Active' : 'Inactive' }}
</div>
| {
"end_byte": 180,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/status-slider.component.html"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.4.html_0_436 | <nav>
<button type="button" (click)="toggleAnimations()">Toggle Animations</button>
<button type="button" (click)="toggle()">Toggle Open/Closed</button>
</nav>
<!-- #docregion toggle-animation -->
<div [@.disabled]="isDisabled">
<div [@childAnimation]="isOpen ? 'open' : 'closed'"
class="open-close-container">
<p>The box is now {{ isOpen ? 'Open' : 'Closed' }}!</p>
</div>
</div>
<!-- #enddocregion toggle-animation --> | {
"end_byte": 436,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.4.html"
} |
angular/adev/src/content/examples/animations/src/app/open-close.component.2.ts_0_658 | import {Component} from '@angular/core';
import {trigger, transition, state, animate, style} from '@angular/animations';
@Component({
standalone: true,
selector: 'app-open-close-boolean',
// #docregion trigger-boolean
animations: [
trigger('openClose', [
state('true', style({height: '*'})),
state('false', style({height: '0px'})),
transition('false <=> true', animate(500)),
]),
],
// #enddocregion trigger-boolean
templateUrl: 'open-close.component.2.html',
styleUrls: ['open-close.component.css'],
})
export class OpenCloseBooleanComponent {
isOpen = false;
toggle() {
this.isOpen = !this.isOpen;
}
}
| {
"end_byte": 658,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/open-close.component.2.ts"
} |
angular/adev/src/content/examples/animations/src/app/toggle-animations-page.component.ts_0_412 | import {Component} from '@angular/core';
import {OpenCloseChildComponent} from './open-close.component.4';
@Component({
standalone: true,
selector: 'app-toggle-animations-child-page',
template: `
<section>
<h2>Toggle Animations</h2>
<app-open-close-toggle></app-open-close-toggle>
</section>
`,
imports: [OpenCloseChildComponent],
})
export class ToggleAnimationsPageComponent {}
| {
"end_byte": 412,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/toggle-animations-page.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/app.component.ts_0_1410 | // #docplaster
// #docregion imports
import {Component, HostBinding} from '@angular/core';
import {
trigger,
state,
style,
animate,
transition,
// ...
} from '@angular/animations';
// #enddocregion imports
import {ChildrenOutletContexts, RouterLink, RouterOutlet} from '@angular/router';
import {slideInAnimation} from './animations';
// #docregion decorator, toggle-app-animations, define
@Component({
standalone: true,
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
imports: [RouterLink, RouterOutlet],
animations: [
// #enddocregion decorator
slideInAnimation,
// #docregion decorator
// #enddocregion toggle-app-animations, define
// animation triggers go here
// #docregion toggle-app-animations, define
],
})
// #enddocregion decorator, define
export class AppComponent {
@HostBinding('@.disabled')
public animationsDisabled = false;
// #enddocregion toggle-app-animations
// #docregion get-route-animations-data
constructor(private contexts: ChildrenOutletContexts) {}
getRouteAnimationData() {
return this.contexts.getContext('primary')?.route?.snapshot?.data?.['animation'];
}
// #enddocregion get-route-animations-data
toggleAnimations() {
this.animationsDisabled = !this.animationsDisabled;
}
// #docregion toggle-app-animations
}
// #enddocregion toggle-app-animations
| {
"end_byte": 1410,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/app.component.ts"
} |
angular/adev/src/content/examples/animations/src/app/insert-remove.component.html_0_323 | <!-- #docplaster -->
<h2>Insert/Remove</h2>
<nav>
<button type="button" (click)="toggle()">Toggle Insert/Remove</button>
</nav>
<!-- #docregion insert-remove-->
@if (isShown) {
<div @myInsertRemoveTrigger class="insert-remove-container">
<p>The box is inserted</p>
</div>
}
<!-- #enddocregion insert-remove-->
| {
"end_byte": 323,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/insert-remove.component.html"
} |
angular/adev/src/content/examples/animations/src/app/querying.component.css_0_449 | section {
border: 1px solid black;
overflow: hidden;
}
section > * {
margin: 1rem;
}
.hero {
display: flex;
align-items: center;
border-radius: 4px;
color: black;
background-color: #DDD;
}
.hero .badge {
display: inline-block;
font-size: small;
color: white;
padding: 0.5rem;
background-color: #3d5157;
margin-right: .8em;
border-radius: 4px 0 0 4px;
align-self: stretch;
}
.hero .name {
height: min-content;
}
| {
"end_byte": 449,
"start_byte": 0,
"url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/animations/src/app/querying.component.css"
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.