_id
stringlengths
21
254
text
stringlengths
1
93.7k
metadata
dict
angular/adev/src/content/examples/structural-directives/e2e/src/app.e2e-spec.ts_0_1838
import {browser, element, by} from 'protractor'; describe('Structural Directives', () => { beforeAll(() => browser.get('')); it('first div should show hero name with *ngIf', async () => { const allDivs = element.all(by.tagName('div')); expect(await allDivs.get(0).getText()).toEqual('Dr. Nice'); }); it('first li should show hero name with *ngFor', async () => { const allLis = element.all(by.tagName('li')); expect(await allLis.get(0).getText()).toEqual('Dr. Nice'); }); it('ngSwitch have two <happy-hero> instances', async () => { const happyHeroEls = element.all(by.tagName('app-happy-hero')); expect(await happyHeroEls.count()).toEqual(2); }); it('should toggle *ngIf="hero" with a button', async () => { const toggleHeroButton = element.all(by.cssContainingText('button', 'Toggle hero')).get(0); const paragraph = element.all(by.cssContainingText('p', 'I turned the corner')); expect(await paragraph.get(0).getText()).toContain('I waved'); await toggleHeroButton.click(); expect(await paragraph.get(0).getText()).not.toContain('I waved'); }); it('appUnless should show 3 paragraph (A)s and (B)s at the start', async () => { const paragraph = element.all(by.css('p.unless')); expect(await paragraph.count()).toEqual(3); for (let i = 0; i < 3; i++) { expect(await paragraph.get(i).getText()).toContain('(A)'); } }); it('appUnless should show 1 paragraph (B) after toggling condition', async () => { const toggleConditionButton = element .all(by.cssContainingText('button', 'Toggle condition')) .get(0); const paragraph = element.all(by.css('p.unless')); await toggleConditionButton.click(); expect(await paragraph.count()).toEqual(1); expect(await paragraph.get(0).getText()).toContain('(B)'); }); });
{ "end_byte": 1838, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/e2e/src/app.e2e-spec.ts" }
angular/adev/src/content/examples/structural-directives/src/index.html_0_296
<!DOCTYPE html> <!-- #docregion --> <html lang="en"> <head> <title>Angular Structural Directives</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": 296, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/index.html" }
angular/adev/src/content/examples/structural-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/structural-directives/src/main.ts" }
angular/adev/src/content/examples/structural-directives/src/app/app.component.html_0_6108
<!-- #docplaster --> <!-- #docregion --> <h1>Structural Directives</h1> <p>Conditional display of hero</p> <blockquote> <!-- #docregion asterisk --> <div *ngIf="hero" class="name">{{hero.name}}</div> <!-- #enddocregion asterisk --> </blockquote> <p>List of heroes</p> <ul> <li *ngFor="let hero of heroes">{{hero.name}}</li> </ul> <hr> <h2 id="ngIf">NgIf</h2> <p *ngIf="true"> Expression is true and ngIf is true. This paragraph is in the DOM. </p> <p *ngIf="false"> Expression is false and ngIf is false. This paragraph is not in the DOM. </p> <p [style.display]="'block'"> Expression sets display to "block". This paragraph is visible. </p> <p [style.display]="'none'"> Expression sets display to "none". This paragraph is hidden but still in the DOM. </p> <h4>NgIf with template</h4> <p>&lt;ng-template&gt; element</p> <!-- #docregion ngif-template --> <ng-template [ngIf]="hero"> <div class="name">{{hero.name}}</div> </ng-template> <!-- #enddocregion ngif-template --> <hr> <h2 id="ng-container">&lt;ng-container&gt;</h2> <h4>*ngIf with a &lt;ng-container&gt;</h4> <button type="button" (click)="hero = hero ? null : heroes[0]">Toggle hero</button> <!-- #docregion ngif-ngcontainer --> <p> I turned the corner <ng-container *ngIf="hero"> and saw {{hero.name}}. I waved </ng-container> and continued on my way. </p> <!-- #enddocregion ngif-ngcontainer --> <p> I turned the corner <span *ngIf="hero"> and saw {{hero.name}}. I waved </span> and continued on my way. </p> <p><em>&lt;select&gt; with &lt;span&gt;</em></p> <div> Pick your favorite hero (<label for="show-sad"><input id="show-sad" type="checkbox" checked (change)="showSad = !showSad">show sad</label>) </div> <select [(ngModel)]="hero"> <span *ngFor="let h of heroes"> <span *ngIf="showSad || h.emotion !== 'sad'"> <option [ngValue]="h">{{h.name}} ({{h.emotion}})</option> </span> </span> </select> <p><em>&lt;select&gt; with &lt;ng-container&gt;</em></p> <!-- #docregion select-ngcontainer --> <div> Pick your favorite hero (<label for="showSad"><input id="showSad" type="checkbox" checked (change)="showSad = !showSad">show sad</label>) </div> <select [(ngModel)]="hero"> <ng-container *ngFor="let h of heroes"> <ng-container *ngIf="showSad || h.emotion !== 'sad'"> <option [ngValue]="h">{{h.name}} ({{h.emotion}})</option> </ng-container> </ng-container> </select> <!-- #enddocregion select-ngcontainer --> <br><br> <hr> <h2 id="ngFor">NgFor</h2> <div class="box"> <p class="code">&lt;div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById" [class.odd]="odd"&gt;</p> <!--#docregion inside-ngfor --> <div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById" [class.odd]="odd"> ({{i}}) {{hero.name}} </div> <!--#enddocregion inside-ngfor --> <p class="code">&lt;ng-template ngFor let-hero [ngForOf]="heroes" let-i="index" let-odd="odd" [ngForTrackBy]="trackById"/&gt;</p> <!--#docregion inside-ngfor --> <ng-template ngFor let-hero [ngForOf]="heroes" let-i="index" let-odd="odd" [ngForTrackBy]="trackById"> <div [class.odd]="odd"> ({{i}}) {{hero.name}} </div> </ng-template> <!--#enddocregion inside-ngfor --> </div> <hr> <h2 id="ngSwitch">NgSwitch</h2> <div>Pick your favorite hero</div> <p> <label for="hero-{{h}}" *ngFor="let h of heroes"> <input id="hero-{{h}}" type="radio" name="heroes" [(ngModel)]="hero" [value]="h">{{h.name}} </label> <label for="none-of-the-above"><input id="none-of-the-above" type="radio" name="heroes" (click)="hero = null">None of the above</label> </p> <h4>NgSwitch</h4> <div [ngSwitch]="hero?.emotion"> <app-happy-hero *ngSwitchCase="'happy'" [hero]="hero!"></app-happy-hero> <app-sad-hero *ngSwitchCase="'sad'" [hero]="hero!"></app-sad-hero> <app-confused-hero *ngSwitchCase="'confused'" [hero]="hero!"></app-confused-hero> <app-unknown-hero *ngSwitchDefault [hero]="hero!"></app-unknown-hero> </div> <h4>NgSwitch with &lt;ng-template&gt;</h4> <div [ngSwitch]="hero?.emotion"> <ng-template ngSwitchCase="happy"> <app-happy-hero [hero]="hero!"></app-happy-hero> </ng-template> <ng-template ngSwitchCase="sad"> <app-sad-hero [hero]="hero!"></app-sad-hero> </ng-template> <ng-template ngSwitchCase="confused"> <app-confused-hero [hero]="hero!"></app-confused-hero> </ng-template > <ng-template ngSwitchDefault> <app-unknown-hero [hero]="hero!"></app-unknown-hero> </ng-template> </div> <hr> <h2 id="appUnless">UnlessDirective</h2> <!-- #docregion toggle-info --> <p> The condition is currently <span [ngClass]="{ 'a': !condition, 'b': condition, 'unless': true }">{{condition}}</span>. <button type="button" (click)="condition = !condition" [ngClass] = "{ 'a': condition, 'b': !condition }" > Toggle condition to {{condition ? 'false' : 'true'}} </button> </p> <!-- #enddocregion toggle-info --> <!-- #docregion appUnless--> <p *appUnless="condition" class="unless a"> (A) This paragraph is displayed because the condition is false. </p> <p *appUnless="!condition" class="unless b"> (B) Although the condition is true, this paragraph is displayed because appUnless is set to false. </p> <!-- #enddocregion appUnless--> <h4>UnlessDirective with template</h4> <!-- #docregion appUnless-1 --> <p *appUnless="condition">Show this sentence unless the condition is true.</p> <!-- #enddocregion appUnless-1 --> <p *appUnless="condition" class="code unless"> (A) &lt;p *appUnless="condition" class="code unless"&gt; </p> <ng-template [appUnless]="condition"> <p class="code unless"> (A) &lt;ng-template [appUnless]="condition"&gt; </p> </ng-template> <hr /> <h2 id="appIfLoaded">IfLoadedDirective</h2> <app-hero></app-hero> <hr /> <h2 id="appTrigonometry">TrigonometryDirective</h2> <!-- #docregion appTrigonometry --> <ul *appTrigonometry="30; sin as s; cos as c; tan as t"> <li>sin(30°): {{ s }}</li> <li>cos(30°): {{ c }}</li> <li>tan(30°): {{ t }}</li> </ul> <!-- #enddocregion appTrigonometry -->
{ "end_byte": 6108, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/app.component.html" }
angular/adev/src/content/examples/structural-directives/src/app/hero.ts_0_298
// #docregion export interface Hero { id: number; name: string; emotion?: string; } export const heroes: Hero[] = [ {id: 1, name: 'Dr. Nice', emotion: 'happy'}, {id: 2, name: 'RubberMan', emotion: 'sad'}, {id: 3, name: 'Windstorm', emotion: 'confused'}, {id: 4, name: 'Magneta'}, ];
{ "end_byte": 298, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/hero.ts" }
angular/adev/src/content/examples/structural-directives/src/app/hero.component.ts_0_669
import {Component} from '@angular/core'; import {CommonModule} from '@angular/common'; import {IfLoadedDirective} from './if-loaded.directive'; import {LoadingState} from './loading-state'; import {Hero, heroes} from './hero'; @Component({ standalone: true, selector: 'app-hero', template: ` <button (click)="onLoadHero()">Load Hero</button> <p *appIfLoaded="heroLoadingState">{{ heroLoadingState.data | json }}</p> `, imports: [CommonModule, IfLoadedDirective], }) export class HeroComponent { heroLoadingState: LoadingState<Hero> = {type: 'loading'}; onLoadHero(): void { this.heroLoadingState = {type: 'loaded', data: heroes[0]}; } }
{ "end_byte": 669, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/hero.component.ts" }
angular/adev/src/content/examples/structural-directives/src/app/unless.directive.ts_0_1411
// #docplaster // #docregion // #docregion no-docs, skeleton import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core'; // #enddocregion skeleton /** * Add the template content to the DOM unless the condition is true. // #enddocregion no-docs * * If the expression assigned to `appUnless` evaluates to a truthy value * then the templated elements are removed from the DOM, * the templated elements are (re)inserted into the DOM. * * <div *appUnless="errorCount" class="success"> * Congrats! Everything is great! * </div> * * ### Syntax * * - `<div *appUnless="condition">...</div>` * - `<ng-template [appUnless]="condition"><div>...</div></ng-template>` * // #docregion no-docs */ // #docregion skeleton @Directive({ standalone: true, selector: '[appUnless]', }) export class UnlessDirective { // #enddocregion skeleton private hasView = false; // #docregion ctor constructor( private templateRef: TemplateRef<any>, private viewContainer: ViewContainerRef, ) {} // #enddocregion ctor // #docregion set @Input() set appUnless(condition: boolean) { if (!condition && !this.hasView) { this.viewContainer.createEmbeddedView(this.templateRef); this.hasView = true; } else if (condition && this.hasView) { this.viewContainer.clear(); this.hasView = false; } } // #enddocregion set // #docregion skeleton }
{ "end_byte": 1411, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/unless.directive.ts" }
angular/adev/src/content/examples/structural-directives/src/app/hero-switch.components.ts_0_1127
// #docregion import {Component, Input} from '@angular/core'; import {Hero} from './hero'; @Component({ standalone: true, selector: 'app-happy-hero', template: 'Wow. You like {{hero.name}}. What a happy hero ... just like you.', }) export class HappyHeroComponent { @Input() hero!: Hero; } @Component({ standalone: true, selector: 'app-sad-hero', template: 'You like {{hero.name}}? Such a sad hero. Are you sad too?', }) export class SadHeroComponent { @Input() hero!: Hero; } @Component({ standalone: true, selector: 'app-confused-hero', template: 'Are you as confused as {{hero.name}}?', }) export class ConfusedHeroComponent { @Input() hero!: Hero; } @Component({ standalone: true, selector: 'app-unknown-hero', template: '{{message}}', }) export class UnknownHeroComponent { @Input() hero!: Hero; get message() { return this.hero && this.hero.name ? `${this.hero.name} is strange and mysterious.` : 'Are you feeling indecisive?'; } } export const heroSwitchComponents = [ HappyHeroComponent, SadHeroComponent, ConfusedHeroComponent, UnknownHeroComponent, ];
{ "end_byte": 1127, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/hero-switch.components.ts" }
angular/adev/src/content/examples/structural-directives/src/app/app.component.ts_0_979
import {Component} from '@angular/core'; import {CommonModule} from '@angular/common'; import {FormsModule} from '@angular/forms'; import {heroSwitchComponents} from './hero-switch.components'; import {HeroComponent} from './hero.component'; import {UnlessDirective} from './unless.directive'; import {TrigonometryDirective} from './trigonometry.directive'; import {Hero, heroes} from './hero'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], imports: [ CommonModule, FormsModule, heroSwitchComponents, HeroComponent, UnlessDirective, TrigonometryDirective, ], }) export class AppComponent { heroes = heroes; hero: Hero | null = this.heroes[0]; // #docregion condition condition = false; // #enddocregion condition logs: string[] = []; showSad = true; status = 'ready'; trackById(index: number, hero: Hero): number { return hero.id; } }
{ "end_byte": 979, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/app.component.ts" }
angular/adev/src/content/examples/structural-directives/src/app/loading-state.ts_0_145
export type Loaded<T> = {type: 'loaded'; data: T}; export type Loading = {type: 'loading'}; export type LoadingState<T> = Loaded<T> | Loading;
{ "end_byte": 145, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/loading-state.ts" }
angular/adev/src/content/examples/structural-directives/src/app/scrap.txt_0_744
// interesting but unused code heroChooser(picker: HTMLFieldSetElement) { let choices = picker.children; this.favoriteHero = undefined; for (let i = 0; i < choices.length; i++) { let choice = choices[i].children[0] as HTMLInputElement; if (choice.checked) { this.favoriteHero = this.heroes[i]; } } } <h4>Switch with *ngFor repeated switchCases using &lt;ng-container&gt;</h4> <!-- #docregion NgSwitch-ngFor --> <div [ngSwitch]="hero.id"> Your favorite hero is ... <ng-container *ngFor="let hero of heroes"> <ng-container *ngSwitchCase="hero.id">{{hero.name}}</ng-container> </ng-container> <ng-container *ngSwitchDefault>None of the above</ng-container> </div> <!-- #enddocregion NgSwitch-ngFor -->
{ "end_byte": 744, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/scrap.txt" }
angular/adev/src/content/examples/structural-directives/src/app/app.component.css_0_862
/* #docregion */ button { min-width: 100px; font-size: 100%; } .box { border: 1px solid gray; max-width: 600px; padding: 4px; } .choices { font-style: italic; } code, .code { background-color: #eee; color: black; font-family: Courier, sans-serif; font-size: 85%; } div.code { width: 400px; } .heroic { font-size: 150%; font-weight: bold; } hr { margin: 40px 0; } .odd { background-color: palegoldenrod; } td, th { text-align: left; vertical-align: top; } p span { color: red; font-size: 70%; } .unless { border: 2px solid; padding: 6px; } p.unless { width: 500px; } button.a, span.a, .unless.a { color: red; border-color: gold; background-color: yellow; font-size: 100%; } button.b, span.b, .unless.b { color: black; border-color: green; background-color: lightgreen; font-size: 100%; }
{ "end_byte": 862, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/app.component.css" }
angular/adev/src/content/examples/structural-directives/src/app/trigonometry.directive.ts_0_1278
import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core'; @Directive({ standalone: true, selector: '[appTrigonometry]', }) export class TrigonometryDirective { private isViewCreated = false; private readonly context = new TrigonometryContext(); @Input('appTrigonometry') set angle(angleInDegrees: number) { const angleInRadians = toRadians(angleInDegrees); this.context.sin = Math.sin(angleInRadians); this.context.cos = Math.cos(angleInRadians); this.context.tan = Math.tan(angleInRadians); if (!this.isViewCreated) { this.viewContainerRef.createEmbeddedView(this.templateRef, this.context); this.isViewCreated = true; } } constructor( private readonly viewContainerRef: ViewContainerRef, private readonly templateRef: TemplateRef<TrigonometryContext>, ) {} // Make sure the template checker knows the type of the context with which the // template of this directive will be rendered static ngTemplateContextGuard( directive: TrigonometryDirective, context: unknown, ): context is TrigonometryContext { return true; } } class TrigonometryContext { sin = 0; cos = 0; tan = 0; } function toRadians(degrees: number): number { return degrees * (Math.PI / 180); }
{ "end_byte": 1278, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/trigonometry.directive.ts" }
angular/adev/src/content/examples/structural-directives/src/app/if-loaded.directive.ts_0_918
import {Directive, Input, TemplateRef, ViewContainerRef} from '@angular/core'; import {Loaded, LoadingState} from './loading-state'; @Directive({ standalone: true, selector: '[appIfLoaded]', }) export class IfLoadedDirective<T> { private isViewCreated = false; @Input('appIfLoaded') set state(state: LoadingState<T>) { if (!this.isViewCreated && state.type === 'loaded') { this.viewContainerRef.createEmbeddedView(this.templateRef); this.isViewCreated = true; } else if (this.isViewCreated && state.type !== 'loaded') { this.viewContainerRef.clear(); this.isViewCreated = false; } } constructor( private readonly viewContainerRef: ViewContainerRef, private readonly templateRef: TemplateRef<unknown>, ) {} static ngTemplateGuard_appIfLoaded<T>( dir: IfLoadedDirective<T>, state: LoadingState<T>, ): state is Loaded<T> { return true; } }
{ "end_byte": 918, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/structural-directives/src/app/if-loaded.directive.ts" }
angular/adev/src/content/examples/resolution-modifiers/BUILD.bazel_0_105
package(default_visibility = ["//visibility:public"]) exports_files(["src/app/self/self.component.ts"])
{ "end_byte": 105, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/BUILD.bazel" }
angular/adev/src/content/examples/resolution-modifiers/e2e/src/app.e2e-spec.ts_0_537
import {browser, element, by} from 'protractor'; describe('Resolution-modifiers-example', () => { beforeAll(() => browser.get('')); it('shows basic flower emoji', async () => { expect(await element.all(by.css('p')).get(0).getText()).toContain('🌸'); }); it('shows basic leaf emoji', async () => { expect(await element.all(by.css('p')).get(1).getText()).toContain('🌿'); }); it('shows tulip in host child', async () => { expect(await element.all(by.css('p')).get(9).getText()).toContain('🌷'); }); });
{ "end_byte": 537, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/e2e/src/app.e2e-spec.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/index.html_0_327
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>DI Resolution Modifiers 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": 327, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/index.html" }
angular/adev/src/content/examples/resolution-modifiers/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/resolution-modifiers/src/main.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/app.component.html_0_287
<h1>DI resolution modifiers</h1> <p>Basic flower service: {{ flower.emoji }}</p> <p>Basic leaf service: {{ leaf.emoji }}</p> <app-optional></app-optional> <app-self></app-self> <app-self-no-data></app-self-no-data> <app-skipself></app-skipself> <app-host-parent></app-host-parent>
{ "end_byte": 287, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/app.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/leaf.service.ts_0_184
import {Injectable} from '@angular/core'; @Injectable({ providedIn: 'root', }) // #docregion leafservice export class LeafService { emoji = '🌿'; } // #enddocregion leafservice
{ "end_byte": 184, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/leaf.service.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/app.component.ts_0_1037
import {Component} from '@angular/core'; import {LeafService} from './leaf.service'; import {FlowerService} from './flower.service'; import {HostComponent} from './host/host.component'; import {OptionalComponent} from './optional/optional.component'; import {SelfComponent} from './self/self.component'; import {HostParentComponent} from './host-parent/host-parent.component'; import {HostChildComponent} from './host-child/host-child.component'; import {SelfNoDataComponent} from './self-no-data/self-no-data.component'; import {SkipselfComponent} from './skipself/skipself.component'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], imports: [ HostComponent, HostChildComponent, HostParentComponent, OptionalComponent, SelfComponent, SelfNoDataComponent, SkipselfComponent, ], }) export class AppComponent { name = 'Angular'; constructor( public flower: FlowerService, public leaf: LeafService, ) {} }
{ "end_byte": 1037, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/app.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/optional.service.ts_0_131
import {Injectable} from '@angular/core'; @Injectable() export class OptionalService {} // This service isn't provided anywhere.
{ "end_byte": 131, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/optional.service.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/app.config.ts_0_288
import {ApplicationConfig} from '@angular/core'; import {provideProtractorTestingSupport} from '@angular/platform-browser'; const appConfig: ApplicationConfig = { providers: [ provideProtractorTestingSupport(), //only needed for docs e2e testing ], }; export default appConfig;
{ "end_byte": 288, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/app.config.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/flower.service.ts_0_182
import {Injectable} from '@angular/core'; @Injectable({ providedIn: 'root', // provide this service in the root ModuleInjector }) export class FlowerService { emoji = '🌸'; }
{ "end_byte": 182, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/flower.service.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.html_0_124
<div class="section"> <h2>&commat;Self() Component (without a provider)</h2> <p>Leaf emoji: {{ leaf?.emoji }}</p> </div>
{ "end_byte": 124, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.ts_0_572
import {Component, Self, Optional} from '@angular/core'; import {LeafService} from '../leaf.service'; // #docregion self-no-data-component @Component({ standalone: true, selector: 'app-self-no-data', templateUrl: './self-no-data.component.html', styleUrls: ['./self-no-data.component.css'], }) export class SelfNoDataComponent { constructor(@Self() @Optional() public leaf?: LeafService) {} } // #enddocregion self-no-data-component // The app doesn't break because the value being available at self is optional. // If you remove @Optional(), the app breaks.
{ "end_byte": 572, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/self-no-data/self-no-data.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host/host.component.ts_0_748
import {Component, Host, Optional} from '@angular/core'; import {FlowerService} from '../flower.service'; import {HostChildComponent} from '../host-child/host-child.component'; // #docregion host-component @Component({ standalone: true, selector: 'app-host', templateUrl: './host.component.html', styleUrls: ['./host.component.css'], // provide the service providers: [{provide: FlowerService, useValue: {emoji: '🌷'}}], imports: [HostChildComponent], }) export class HostComponent { // use @Host() in the constructor when injecting the service constructor(@Host() @Optional() public flower?: FlowerService) {} } // #enddocregion host-component // if you take out @Host() and the providers array, flower will be red hibiscus
{ "end_byte": 748, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host/host.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host/host.component.html_0_187
<div class="section"> <h2>&commat;Host() Component</h2> <p>Flower emoji: {{ flower?.emoji }}</p> <p><i>(&commat;Host() stops it here)</i></p> <app-host-child></app-host-child> </div>
{ "end_byte": 187, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host/host.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host/host.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host/host.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host-child/host-child.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host-child/host-child.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host-child/host-child.component.html_0_115
<div class="section"> <h2>Child of &commat;Host() Component</h2> <p>Flower emoji: {{ flower.emoji }}</p> </div>
{ "end_byte": 115, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host-child/host-child.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host-child/host-child.component.ts_0_331
import {Component} from '@angular/core'; import {FlowerService} from '../flower.service'; @Component({ standalone: true, selector: 'app-host-child', templateUrl: './host-child.component.html', styleUrls: ['./host-child.component.css'], }) export class HostChildComponent { constructor(public flower: FlowerService) {} }
{ "end_byte": 331, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host-child/host-child.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/optional/optional.component.html_0_328
<div class="section"> <h2>&commat;Optional() Component</h2> <p>This component still works even though the OptionalService (notice &commat;Optional() in the constructor isn't provided or configured anywhere. Angular goes through tree and visibility rules, and if it doesn't find the requested service, returns null.</p> </div>
{ "end_byte": 328, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/optional/optional.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/optional/optional.component.ts_0_603
import {Component, Optional} from '@angular/core'; import {OptionalService} from '../optional.service'; @Component({ standalone: true, selector: 'app-optional', templateUrl: './optional.component.html', styleUrls: ['./optional.component.css'], }) // #docregion optional-component export class OptionalComponent { constructor(@Optional() public optional?: OptionalService) {} } // #enddocregion optional-component // The OptionalService isn't provided here, in the @Injectable() // providers array, or in the NgModule. If you remove @Optional() // from the constructor, you'll get an error.
{ "end_byte": 603, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/optional/optional.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/optional/optional.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/optional/optional.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/self/self.component.ts_0_566
import {Component, Self} from '@angular/core'; import {FlowerService} from '../flower.service'; // #docregion self-component @Component({ standalone: true, selector: 'app-self', templateUrl: './self.component.html', styleUrls: ['./self.component.css'], providers: [{provide: FlowerService, useValue: {emoji: '🌷'}}], }) export class SelfComponent { constructor(@Self() public flower: FlowerService) {} } // #enddocregion self-component // This component provides the FlowerService so the injector // doesn't have to look further up the injector tree
{ "end_byte": 566, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/self/self.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/self/self.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/self/self.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/self/self.component.html_0_106
<div class="section"> <h2>&commat;Self() Component</h2> <p>Flower emoji: {{ flower.emoji }}</p> </div>
{ "end_byte": 106, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/self/self.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/skipself/skipself.component.html_0_106
<div class="section"> <h2>&commat;SkipSelf() Component</h2> <p>Leaf emoji: {{ leaf.emoji }}</p> </div>
{ "end_byte": 106, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/skipself/skipself.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/skipself/skipself.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/skipself/skipself.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/skipself/skipself.component.ts_0_672
import {Component, SkipSelf} from '@angular/core'; import {LeafService} from '../leaf.service'; // #docregion skipself-component @Component({ standalone: true, selector: 'app-skipself', templateUrl: './skipself.component.html', styleUrls: ['./skipself.component.css'], // Angular would ignore this LeafService instance providers: [{provide: LeafService, useValue: {emoji: '🍁'}}], }) export class SkipselfComponent { // Use @SkipSelf() in the constructor constructor(@SkipSelf() public leaf: LeafService) {} } // #enddocregion skipself-component // @SkipSelf(): Specifies that the dependency resolution should start from the parent injector, not here.
{ "end_byte": 672, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/skipself/skipself.component.ts" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host-parent/host-parent.component.css_0_74
.section { border: 2px solid #369; padding: 1rem; margin: 1rem 0; }
{ "end_byte": 74, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host-parent/host-parent.component.css" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host-parent/host-parent.component.html_0_138
<div class="section"> <h2>Parent of &commat;Host() Component</h2> <p>Flower emoji: {{ flower.emoji }}</p> <app-host></app-host> </div>
{ "end_byte": 138, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host-parent/host-parent.component.html" }
angular/adev/src/content/examples/resolution-modifiers/src/app/host-parent/host-parent.component.ts_0_485
import {Component} from '@angular/core'; import {FlowerService} from '../flower.service'; import {HostComponent} from '../host/host.component'; @Component({ standalone: true, selector: 'app-host-parent', templateUrl: './host-parent.component.html', styleUrls: ['./host-parent.component.css'], providers: [{provide: FlowerService, useValue: {emoji: '🌺'}}], imports: [HostComponent], }) export class HostParentComponent { constructor(public flower: FlowerService) {} }
{ "end_byte": 485, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/resolution-modifiers/src/app/host-parent/host-parent.component.ts" }
angular/adev/src/content/examples/angular-compiler-options/BUILD.bazel_0_120
package(default_visibility = ["//visibility:public"]) exports_files([ "tsconfig.app.json", "tsconfig.json", ])
{ "end_byte": 120, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/angular-compiler-options/BUILD.bazel" }
angular/adev/src/content/examples/angular-compiler-options/e2e/src/app.e2e-spec.ts_0_538
import {AppPage} from './app.po'; import {browser, logging} from 'protractor'; describe('workspace-project App', () => { let page: AppPage; beforeEach(() => { page = new AppPage(); }); // Add your e2e tests here afterEach(async () => { // Assert that there are no errors emitted from the browser const logs = await browser.manage().logs().get(logging.Type.BROWSER); expect(logs).not.toContain( jasmine.objectContaining({ level: logging.Level.SEVERE, } as logging.Entry), ); }); });
{ "end_byte": 538, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/angular-compiler-options/e2e/src/app.e2e-spec.ts" }
angular/adev/src/content/examples/angular-compiler-options/src/index.html_0_295
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Ponyracer</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": 295, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/angular-compiler-options/src/index.html" }
angular/adev/src/content/examples/angular-compiler-options/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/angular-compiler-options/src/main.ts" }
angular/adev/src/content/examples/angular-compiler-options/src/app/app.component.html_0_64
<h1>Replace the src folder in this {{ title }} with yours.</h1>
{ "end_byte": 64, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/angular-compiler-options/src/app/app.component.html" }
angular/adev/src/content/examples/angular-compiler-options/src/app/app.component.spec.ts_0_479
import {TestBed} from '@angular/core/testing'; import {AppComponent} from './app.component'; describe('AppComponent', () => { beforeEach(async () => { await TestBed.configureTestingModule({ declarations: [AppComponent], }).compileComponents(); }); it('should create the app', () => { const fixture = TestBed.createComponent(AppComponent); const app = fixture.componentInstance; expect(app).toBeTruthy(); }); // Add your unit tests here });
{ "end_byte": 479, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/angular-compiler-options/src/app/app.component.spec.ts" }
angular/adev/src/content/examples/angular-compiler-options/src/app/app.component.ts_0_230
import {Component} from '@angular/core'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'], }) export class AppComponent { title = 'example'; }
{ "end_byte": 230, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/angular-compiler-options/src/app/app.component.ts" }
angular/adev/src/content/examples/attribute-directives/BUILD.bazel_0_448
package(default_visibility = ["//visibility:public"]) exports_files([ "src/app/app.component.1.html", "src/app/app.component.1.ts", "src/app/app.component.avoid.html", "src/app/app.component.html", "src/app/app.component.ts", "src/app/highlight.directive.0.ts", "src/app/highlight.directive.1.ts", "src/app/highlight.directive.2.ts", "src/app/highlight.directive.3.ts", "src/app/highlight.directive.ts", ])
{ "end_byte": 448, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/BUILD.bazel" }
angular/adev/src/content/examples/attribute-directives/e2e/src/app.e2e-spec.ts_0_1027
import {browser, element, by} from 'protractor'; describe('Attribute directives', () => { const title = 'My First Attribute Directive'; beforeAll(() => browser.get('')); it(`should display correct title: ${title}`, async () => { expect(await element(by.css('h1')).getText()).toEqual(title); }); it('should be able to select green highlight', async () => { const highlightedEle = element(by.cssContainingText('p', 'Highlight me!')); const lightGreen = 'rgba(144, 238, 144, 1)'; const getBgColor = () => highlightedEle.getCssValue('background-color'); expect(await highlightedEle.getCssValue('background-color')).not.toEqual(lightGreen); const greenRb = element.all(by.css('input')).get(0); await greenRb.click(); await browser.actions().mouseMove(highlightedEle).perform(); // Wait for up to 4s for the background color to be updated, // to account for slow environments (e.g. CI). await browser.wait(async () => (await getBgColor()) === lightGreen, 4000); }); });
{ "end_byte": 1027, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/e2e/src/app.e2e-spec.ts" }
angular/adev/src/content/examples/attribute-directives/src/index.html_0_285
<!-- #docregion --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Attribute Directives</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <app-root></app-root> </body> </html>
{ "end_byte": 285, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/index.html" }
angular/adev/src/content/examples/attribute-directives/src/main.ts_0_289
// #docregion import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; bootstrapApplication(AppComponent, { providers: [provideProtractorTestingSupport()], }).catch((err) => console.error(err));
{ "end_byte": 289, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/main.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/app.component.html_0_1204
<!-- #docregion v2, --> <h1>My First Attribute Directive</h1> <h2>Pick a highlight color</h2> <div> <input type="radio" name="colors" (click)="color='lightgreen'">Green <input type="radio" name="colors" (click)="color='yellow'">Yellow <input type="radio" name="colors" (click)="color='cyan'">Cyan </div> <!-- #docregion color --> <p [appHighlight]="color">Highlight me!</p> <!-- #enddocregion color, v2 --> <!-- #docregion defaultColor --> <p [appHighlight]="color" defaultColor="violet"> Highlight me too! </p> <!-- #enddocregion defaultColor, --> <hr /> <h2>Mouse over the following lines to see fixed highlights</h2> <p [appHighlight]="'yellow'">Highlighted in yellow</p> <p appHighlight="orange">Highlighted in orange</p> <hr /> <h2>ngNonBindable</h2> <!-- #docregion ngNonBindable --> <p>Use ngNonBindable to stop evaluation.</p> <p ngNonBindable>This should not evaluate: {{ 1 + 1 }}</p> <!-- #enddocregion ngNonBindable --> <!-- #docregion ngNonBindable-with-directive --> <h3>ngNonBindable with a directive</h3> <div ngNonBindable [appHighlight]="'yellow'">This should not evaluate: {{ 1 +1 }}, but will highlight yellow. </div> <!-- #enddocregion ngNonBindable-with-directive -->
{ "end_byte": 1204, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/app.component.html" }
angular/adev/src/content/examples/attribute-directives/src/app/highlight.directive.3.ts_0_678
// #docregion, imports import {Directive, ElementRef, HostListener, Input} from '@angular/core'; // #enddocregion imports @Directive({ standalone: true, selector: '[appHighlight]', }) export class HighlightDirective { constructor(private el: ElementRef) {} // #docregion input @Input() appHighlight = ''; // #enddocregion input // #docregion mouse-enter @HostListener('mouseenter') onMouseEnter() { this.highlight(this.appHighlight || 'red'); } // #enddocregion mouse-enter @HostListener('mouseleave') onMouseLeave() { this.highlight(''); } private highlight(color: string) { this.el.nativeElement.style.backgroundColor = color; } }
{ "end_byte": 678, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/highlight.directive.3.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/highlight.directive.ts_0_696
import {Directive, ElementRef, HostListener, Input} from '@angular/core'; @Directive({ standalone: true, selector: '[appHighlight]', }) export class HighlightDirective { constructor(private el: ElementRef) {} // #docregion defaultColor @Input() defaultColor = ''; // #enddocregion defaultColor @Input() appHighlight = ''; // #docregion mouse-enter @HostListener('mouseenter') onMouseEnter() { this.highlight(this.appHighlight || this.defaultColor || 'red'); } // #enddocregion mouse-enter @HostListener('mouseleave') onMouseLeave() { this.highlight(''); } private highlight(color: string) { this.el.nativeElement.style.backgroundColor = color; } }
{ "end_byte": 696, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/highlight.directive.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/app.component.1.ts_0_304
import {Component} from '@angular/core'; import {HighlightDirective} from './highlight.directive'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.1.html', imports: [HighlightDirective], }) // #docregion class export class AppComponent { color = 'yellow'; }
{ "end_byte": 304, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/app.component.1.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/highlight.directive.2.ts_0_661
// #docplaster // #docregion imports import {Directive, ElementRef, HostListener} from '@angular/core'; // #enddocregion imports import {Input} from '@angular/core'; // #docregion @Directive({ standalone: true, selector: '[appHighlight]', }) export class HighlightDirective { constructor(private el: ElementRef) {} // #docregion mouse-methods @HostListener('mouseenter') onMouseEnter() { this.highlight('yellow'); } @HostListener('mouseleave') onMouseLeave() { this.highlight(''); } private highlight(color: string) { this.el.nativeElement.style.backgroundColor = color; } // #enddocregion mouse-methods } // #enddocregion
{ "end_byte": 661, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/highlight.directive.2.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/app.component.avoid.html_0_104
<!-- #docregion unsupported --> <p app:Highlight>This is invalid</p> <!-- #enddocregion unsupported -->
{ "end_byte": 104, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/app.component.avoid.html" }
angular/adev/src/content/examples/attribute-directives/src/app/app.component.ts_0_310
// #docregion import {Component} from '@angular/core'; import {HighlightDirective} from './highlight.directive'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', imports: [HighlightDirective], }) // #docregion class export class AppComponent { color = ''; }
{ "end_byte": 310, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/app.component.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/highlight.directive.1.ts_0_274
// #docregion import {Directive, ElementRef} from '@angular/core'; @Directive({ standalone: true, selector: '[appHighlight]', }) export class HighlightDirective { constructor(private el: ElementRef) { this.el.nativeElement.style.backgroundColor = 'yellow'; } }
{ "end_byte": 274, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/highlight.directive.1.ts" }
angular/adev/src/content/examples/attribute-directives/src/app/app.component.1.html_0_332
<!-- #docregion --> <h1>My First Attribute Directive</h1> <!-- #docregion applied --> <p appHighlight>Highlight me!</p> <!-- #enddocregion applied --> <p appHighlight="yellow">Highlighted in yellow</p> <p [appHighlight]="'orange'">Highlighted in orange</p> <p [appHighlight]="color">Highlighted with parent component's color</p>
{ "end_byte": 332, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/app.component.1.html" }
angular/adev/src/content/examples/attribute-directives/src/app/highlight.directive.0.ts_0_157
// #docregion import {Directive} from '@angular/core'; @Directive({ standalone: true, selector: '[appHighlight]', }) export class HighlightDirective {}
{ "end_byte": 157, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/attribute-directives/src/app/highlight.directive.0.ts" }
angular/adev/src/content/examples/service-worker-getting-started/BUILD.bazel_0_247
package(default_visibility = ["//visibility:public"]) exports_files([ "src/app/check-for-update.service.ts", "src/app/handle-unrecoverable-state.service.ts", "src/app/log-update.service.ts", "src/app/prompt-update.service.ts", ])
{ "end_byte": 247, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/BUILD.bazel" }
angular/adev/src/content/examples/service-worker-getting-started/e2e/src/app.e2e-spec.ts_0_1492
import {AppPage} from './app.po'; import {element, by} from 'protractor'; describe('sw-example App', () => { let page: AppPage; beforeEach(async () => { page = new AppPage(); await page.navigateTo(); }); it('should display welcome message', async () => { expect(await page.getTitleText()).toEqual('Welcome to Service Workers!'); }); it('should display the Angular logo', async () => { const logo = element(by.css('img')); expect(await logo.isPresent()).toBe(true); }); it('should show a header for the list of links', async () => { const listHeader = element(by.css('app-root > h2')); expect(await listHeader.getText()).toEqual('Here are some links to help you start:'); }); it('should show a list of links', async () => { const items = await element.all(by.css('ul > li > h2 > a')); expect(items.length).toBe(4); expect(await items[0].getText()).toBe('Angular Service Worker Intro'); expect(await items[1].getText()).toBe('Tour of Heroes'); expect(await items[2].getText()).toBe('CLI Documentation'); expect(await items[3].getText()).toBe('Angular blog'); }); // Check for a rejected promise as the service worker is not enabled it('SwUpdate.checkForUpdate() should return a rejected promise', async () => { const button = element(by.css('button')); const rejectMessage = element(by.css('p')); await button.click(); expect(await rejectMessage.getText()).toContain('rejected: '); }); });
{ "end_byte": 1492, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/e2e/src/app.e2e-spec.ts" }
angular/adev/src/content/examples/service-worker-getting-started/src/index.html_0_166
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>SwExample</title> <base href="/"> </head> <body> <app-root></app-root> </body> </html>
{ "end_byte": 166, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/index.html" }
angular/adev/src/content/examples/service-worker-getting-started/src/main.ts_0_278
import {bootstrapApplication, provideProtractorTestingSupport} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; bootstrapApplication(AppComponent, { providers: [ provideProtractorTestingSupport(), // essential for e2e testing ], });
{ "end_byte": 278, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/main.ts" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/app.component.html_0_1304
<!--The content below is only a placeholder and can be replaced.--> <div style="text-align:center"> <h1> Welcome to {{ title }}! </h1> <img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg=="> </div> <button type="button" id="check" (click)="updateCheck()">Check for Update</button> <p id="checkResult">{{ updateCheckText }}</p> <h2>Here are some links to help you start: </h2> <ul> <li> <h2><a target="_blank" rel="noopener" href="https://angular.dev/ecosystem/service-workers">Angular Service Worker Intro</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">CLI Documentation</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https://blog.angular.dev/">Angular blog</a></h2> </li> </ul>
{ "end_byte": 1304, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/app.component.html" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/check-for-update.service.ts_0_979
import {ApplicationRef, Injectable} from '@angular/core'; import {SwUpdate} from '@angular/service-worker'; import {concat, interval} from 'rxjs'; import {first} from 'rxjs/operators'; @Injectable({providedIn: 'root'}) export class CheckForUpdateService { constructor(appRef: ApplicationRef, updates: SwUpdate) { // Allow the app to stabilize first, before starting // polling for updates with `interval()`. const appIsStable$ = appRef.isStable.pipe(first((isStable) => isStable === true)); const everySixHours$ = interval(6 * 60 * 60 * 1000); const everySixHoursOnceAppIsStable$ = concat(appIsStable$, everySixHours$); everySixHoursOnceAppIsStable$.subscribe(async () => { try { const updateFound = await updates.checkForUpdate(); console.log(updateFound ? 'A new version is available.' : 'Already on the latest version.'); } catch (err) { console.error('Failed to check for updates:', err); } }); } }
{ "end_byte": 979, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/check-for-update.service.ts" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/handle-unrecoverable-state.service.ts_0_550
import {Injectable} from '@angular/core'; import {SwUpdate} from '@angular/service-worker'; function notifyUser(message: string): void {} // #docregion sw-unrecoverable-state @Injectable({providedIn: 'root'}) export class HandleUnrecoverableStateService { constructor(updates: SwUpdate) { updates.unrecoverable.subscribe((event) => { notifyUser( 'An error occurred that we cannot recover from:\n' + event.reason + '\n\nPlease reload the page.', ); }); } } // #enddocregion sw-unrecoverable-state
{ "end_byte": 550, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/handle-unrecoverable-state.service.ts" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/app.component.ts_0_518
import {Component} from '@angular/core'; import {SwUpdate} from '@angular/service-worker'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { title = 'Service Workers'; updateCheckText = ''; constructor(private update: SwUpdate) {} updateCheck(): void { this.update .checkForUpdate() .then(() => (this.updateCheckText = 'resolved')) .catch((err) => (this.updateCheckText = `rejected: ${err.message}`)); } }
{ "end_byte": 518, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/app.component.ts" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/readme.md_0_352
# Instructions for Angular Universal Example Download This is the downloaded sample code for the [Angular Universal (Standalone) guide](https://angular.dev/guide/ssr). ## Install and Run 1. `npm install` to install the `node_module` packages 2. `npm run dev:ssr` to launch the server and application 3. Launch the browser to `http://localhost:4200`
{ "end_byte": 352, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/readme.md" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/log-update.service.ts_0_842
import {Injectable} from '@angular/core'; import {SwUpdate, VersionReadyEvent} from '@angular/service-worker'; // #docregion sw-update @Injectable({providedIn: 'root'}) export class LogUpdateService { constructor(updates: SwUpdate) { updates.versionUpdates.subscribe((evt) => { switch (evt.type) { case 'VERSION_DETECTED': console.log(`Downloading new app version: ${evt.version.hash}`); break; case 'VERSION_READY': console.log(`Current app version: ${evt.currentVersion.hash}`); console.log(`New app version ready for use: ${evt.latestVersion.hash}`); break; case 'VERSION_INSTALLATION_FAILED': console.log(`Failed to install app version '${evt.version.hash}': ${evt.error}`); break; } }); } } // #enddocregion sw-update
{ "end_byte": 842, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/log-update.service.ts" }
angular/adev/src/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts_0_1247
// #docplaster import {Injectable} from '@angular/core'; // #docregion sw-replicate-available import {filter, map} from 'rxjs/operators'; // #enddocregion sw-replicate-available import {SwUpdate, VersionReadyEvent} from '@angular/service-worker'; function promptUser(event: VersionReadyEvent): boolean { return true; } // #docregion sw-version-ready @Injectable({providedIn: 'root'}) export class PromptUpdateService { constructor(swUpdate: SwUpdate) { swUpdate.versionUpdates .pipe(filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY')) .subscribe((evt) => { if (promptUser(evt)) { // Reload the page to update to the latest version. document.location.reload(); } }); // #enddocregion sw-version-ready // #docregion sw-replicate-available // ... const updatesAvailable = swUpdate.versionUpdates.pipe( filter((evt): evt is VersionReadyEvent => evt.type === 'VERSION_READY'), map((evt) => ({ type: 'UPDATE_AVAILABLE', current: evt.currentVersion, available: evt.latestVersion, })), ); // #enddocregion sw-replicate-available // #docregion sw-version-ready } } // #enddocregion sw-version-ready
{ "end_byte": 1247, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/service-worker-getting-started/src/app/prompt-update.service.ts" }
angular/adev/src/content/examples/errors/BUILD.bazel_0_30
exports_files(glob(["**/*"]))
{ "end_byte": 30, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/errors/BUILD.bazel" }
angular/adev/src/content/examples/errors/cyclic-imports/parent.component.ts_0_243
import {Component} from '@angular/core'; import {ChildComponent} from './child.component'; @Component({ standalone: true, selector: 'app-parent', imports: [ChildComponent], template: '<app-child/>', }) export class ParentComponent {}
{ "end_byte": 243, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/errors/cyclic-imports/parent.component.ts" }
angular/adev/src/content/examples/errors/cyclic-imports/child.component.ts_0_263
import {Component} from '@angular/core'; import {ParentComponent} from './parent.component'; @Component({ standalone: true, selector: 'app-child', template: 'The child!', }) export class ChildComponent { constructor(private parent: ParentComponent) {} }
{ "end_byte": 263, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/errors/cyclic-imports/child.component.ts" }
angular/adev/src/content/examples/i18n/readme.md_0_869
# Angular i18n Internationalization Example This sample comes from the Angular documentation's "[Example Angular Internationalization application](https://angular.dev/guide/i18n/example)" page. ## Install and Run the Download 1. `npm install` the node_module packages 2. `npm start` to see it run in English 3. `npm run start:fr` to see it run with French translation. >See the scripts in `package.json` for an explanation of these commands. ## Run in Stackblitz Stackblitz compiles and runs the English version by default. To see the example translate to French with Angular i18n: 1. Open the `project.json` file and add the following to the bottom: ```json "stackblitz": { "startCommand": "npm run start:fr" } ``` 1. Click the "Fork" button in the stackblitz header. That makes a new copy for you with this change and re-runs the example in French.
{ "end_byte": 869, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/readme.md" }
angular/adev/src/content/examples/i18n/BUILD.bazel_0_448
package(default_visibility = ["//visibility:public"]) exports_files([ "angular.json", "doc-files/apache2.conf", "doc-files/app.component.html", "doc-files/commands.sh", "doc-files/locale_plural_function.ts", "doc-files/main.1.ts", "doc-files/messages.fr.xlf.html", "doc-files/nginx.conf", "doc-files/rendered-output.html", "src/app/app.component.html", "src/app/app.component.ts", "src/main.ts", ])
{ "end_byte": 448, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/BUILD.bazel" }
angular/adev/src/content/examples/i18n/doc-files/app.component.html_0_1266
<!--#docregion greeting--> <h1>Hello i18n!</h1> <!--#enddocregion greeting--> <!--#docregion i18n-attribute--> <h1 i18n>Hello i18n!</h1> <!--#enddocregion i18n-attribute--> <!--#docregion i18n-attribute-desc--> <h1 i18n="An introduction header for this sample">Hello i18n!</h1> <!--#enddocregion i18n-attribute-desc--> <!--#docregion i18n-attribute-meaning--> <h1 i18n="site header|An introduction header for this sample">Hello i18n!</h1> <!--#enddocregion i18n-attribute-meaning--> <!--#docregion i18n-attribute-id--> <h1 i18n="An introduction header for this sample@@introductionHeader">Hello i18n!</h1> <!--#enddocregion i18n-attribute-id--> <!--#docregion i18n-attribute-meaning-and-id--> <h1 i18n="site header|An introduction header for this sample@@introductionHeader">Hello i18n!</h1> <!--#enddocregion i18n-attribute-meaning-and-id--> <!--#docregion i18n-attribute-solo-id--> <h1 i18n="@@introductionHeader">Hello i18n!</h1> <!--#enddocregion i18n-attribute-solo-id--> <!--#docregion i18n-title--> <img [src]="logo" title="Angular logo" alt="Angular logo"> <!--#enddocregion i18n-title--> <!--#docregion i18n-duplicate-custom-id--> <h3 i18n="@@myId">Hello</h3> <!-- ... --> <p i18n="@@myId">Good bye</p> <!--#enddocregion i18n-duplicate-custom-id-->
{ "end_byte": 1266, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/app.component.html" }
angular/adev/src/content/examples/i18n/doc-files/messages.fr.xlf.html_0_4554
<!-- The `messages.fr.xlf` after translation for documentation purposes --> <!-- #docregion --> <?xml version="1.0" encoding="UTF-8" ?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template"> <body> <!-- #docregion translated-hello-before --> <trans-unit id="introductionHeader" datatype="html"> <source>Hello i18n!</source> <note priority="1" from="description">An introduction header for this sample</note> <note priority="1" from="meaning">User welcome</note> </trans-unit> <!-- #enddocregion translated-hello-before --> <!-- #docregion translated-hello --> <!-- #docregion custom-id --> <trans-unit id="introductionHeader" datatype="html"> <!-- #enddocregion custom-id --> <source>Hello i18n!</source> <target>Bonjour i18n !</target> <note priority="1" from="description">An introduction header for this sample</note> <note priority="1" from="meaning">User welcome</note> </trans-unit> <!-- #enddocregion translated-hello --> <!-- #docregion translated-other-nodes --> <!-- #docregion generated-id --> <trans-unit id="ba0cc104d3d69bf669f97b8d96a4c5d8d9559aa3" datatype="html"> <!-- #enddocregion generated-id --> <source>I don&apos;t output any element</source> <target>Je n'affiche aucun élément</target> </trans-unit> <trans-unit id="701174153757adf13e7c24a248c8a873ac9f5193" datatype="html"> <source>Angular logo</source> <target>Logo d'Angular</target> </trans-unit> <!-- #enddocregion translated-other-nodes --> <!-- #docregion translated-plural --> <trans-unit id="5a134dee893586d02bffc9611056b9cadf9abfad" datatype="html"> <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago} }</source> <target>{VAR_PLURAL, plural, =0 {à l'instant} =1 {il y a une minute} other {il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes} }</target> </trans-unit> <!-- #enddocregion translated-plural --> <!-- #docregion translated-select --> <!-- #docregion translate-select-1 --> <trans-unit id="f99f34ac9bd4606345071bd813858dec29f3b7d1" datatype="html"> <source>The author is <x id="ICU" equiv-text="{gender, select, male {...} female {...} other {...}}"/></source> <target>L'auteur est <x id="ICU" equiv-text="{gender, select, male {...} female {...} other {...}}"/></target> </trans-unit> <!-- #enddocregion translate-select-1 --> <!-- #docregion translate-select-2 --> <trans-unit id="eff74b75ab7364b6fa888f1cbfae901aaaf02295" datatype="html"> <source>{VAR_SELECT, select, male {male} female {female} other {other} }</source> <target>{VAR_SELECT, select, male {un homme} female {une femme} other {autre} }</target> </trans-unit> <!-- #enddocregion translate-select-2 --> <!-- #enddocregion translated-select --> <!-- #docregion translate-nested --> <!-- #docregion translate-nested-1 --> <trans-unit id="972cb0cf3e442f7b1c00d7dab168ac08d6bdf20c" datatype="html"> <source>Updated: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source> <target>Mis à jour: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target> </trans-unit> <!-- #enddocregion translate-nested-1 --> <!-- #docregion translate-nested-2 --> <trans-unit id="7151c2e67748b726f0864fc443861d45df21d706" datatype="html"> <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago by {VAR_SELECT, select, male {male} female {female} other {other} }} }</source> <target>{VAR_PLURAL, plural, =0 {à l'instant} =1 {il y a une minute} other {il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes par {VAR_SELECT, select, male {un homme} female {une femme} other {autre} }} }</target> </trans-unit> <!-- #enddocregion translate-nested-2 --> <!-- #enddocregion translate-nested --> <!-- #docregion i18n-duplicate-custom-id --> <trans-unit id="myId" datatype="html"> <source>Hello</source> <target state="new">Bonjour</target> </trans-unit> <!-- #enddocregion i18n-duplicate-custom-id --> </body> </file> </xliff>
{ "end_byte": 4554, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/messages.fr.xlf.html" }
angular/adev/src/content/examples/i18n/doc-files/commands.sh_0_901
# #docregion add-localize ng add @angular/localize # #enddocregion add-localize # #docregion extract-i18n-default ng extract-i18n # #enddocregion extract-i18n-default # #docregion extract-i18n-output-path ng extract-i18n --output-path src/locale # #enddocregion extract-i18n-output-path # #docregion extract-i18n-formats ng extract-i18n --format=xlf ng extract-i18n --format=xlf2 ng extract-i18n --format=xmb ng extract-i18n --format=json ng extract-i18n --format=arb # #enddocregion extract-i18n-formats # #docregion extract-i18n-out-file ng extract-i18n --out-file source.xlf # #enddocregion extract-i18n-out-file # #docregion build-localize ng build --localize # #enddocregion build-localize # #docregion serve-french ng serve --configuration=fr # #enddocregion serve-french # #docregion build-production-french ng build --configuration=production,fr # #enddocregion build-production-french
{ "end_byte": 901, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/commands.sh" }
angular/adev/src/content/examples/i18n/doc-files/app.module.ts_0_400
// For documenting NgModule Apps only // #docregion import {LOCALE_ID, NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {AppComponent} from '../src/app/app.component'; @NgModule({ imports: [BrowserModule], declarations: [AppComponent], providers: [{provide: LOCALE_ID, useValue: 'fr'}], bootstrap: [AppComponent], }) export class AppModule {}
{ "end_byte": 400, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/app.module.ts" }
angular/adev/src/content/examples/i18n/doc-files/app.locale_data_extra.ts_0_220
import {registerLocaleData} from '@angular/common'; import localeFrExtra from '@angular/common/locales/extra/fr'; import localeFr from '@angular/common/locales/fr'; registerLocaleData(localeFr, 'fr-FR', localeFrExtra);
{ "end_byte": 220, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/app.locale_data_extra.ts" }
angular/adev/src/content/examples/i18n/doc-files/main.1.ts_0_151
import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; bootstrapApplication(AppComponent);
{ "end_byte": 151, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/main.1.ts" }
angular/adev/src/content/examples/i18n/doc-files/app.locale_data.ts_0_187
import {registerLocaleData} from '@angular/common'; import localeFr from '@angular/common/locales/fr'; // the second parameter 'fr-FR' is optional registerLocaleData(localeFr, 'fr-FR');
{ "end_byte": 187, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/app.locale_data.ts" }
angular/adev/src/content/examples/i18n/doc-files/rendered-output.html_0_44
<h3>Bonjour</h3> <!-- ... --> <p>Bonjour</p>
{ "end_byte": 44, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/rendered-output.html" }
angular/adev/src/content/examples/i18n/doc-files/locale_plural_function.ts_0_212
/* eslint-disable */ // #docregion function plural(n: number): number { let i = Math.floor(Math.abs(n)), v = n.toString().replace(/^[^.]*\.?/, '').length; if (i === 1 && v === 0) return 1; return 5; }
{ "end_byte": 212, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/doc-files/locale_plural_function.ts" }
angular/adev/src/content/examples/i18n/e2e/src/app.e2e-spec.ts_0_1696
import {browser, element, by} from 'protractor'; describe('i18n E2E Tests', () => { beforeEach(() => browser.get('')); it('should display i18n translated welcome: Bonjour !', async () => { expect(await element(by.css('h1')).getText()).toEqual('Bonjour i18n !'); }); it('should display the node texts without elements', async () => { expect(await element(by.css('app-root')).getText()).toContain(`Je n'affiche aucun élément`); }); it('should display the translated title attribute', async () => { const title = await element(by.css('img')).getAttribute('title'); expect(title).toBe(`Logo d'Angular`); }); it('should display the ICU plural expression', async () => { expect(await element.all(by.css('span')).get(0).getText()).toBe(`Mis à jour à l'instant`); }); it('should display the ICU select expression', async () => { const selectIcuExp = element.all(by.css('span')).get(1); expect(await selectIcuExp.getText()).toBe(`L'auteur est une femme`); await element.all(by.css('button')).get(2).click(); expect(await selectIcuExp.getText()).toBe(`L'auteur est un homme`); }); it('should display the nested expression', async () => { const nestedExp = element.all(by.css('span')).get(2); const incBtn = element.all(by.css('button')).get(0); expect(await nestedExp.getText()).toBe(`Mis à jour: à l'instant`); await incBtn.click(); expect(await nestedExp.getText()).toBe(`Mis à jour: il y a une minute`); await incBtn.click(); await incBtn.click(); await element.all(by.css('button')).get(4).click(); expect(await nestedExp.getText()).toBe(`Mis à jour: il y a 3 minutes par autre`); }); });
{ "end_byte": 1696, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/e2e/src/app.e2e-spec.ts" }
angular/adev/src/content/examples/i18n/src/index.html_0_318
<!-- #docregion --> <!DOCTYPE html> <html lang="en"> <head> <base href="/"> <title>Angular i18n example</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <app-root>Loading...</app-root> </body> </html> <!-- #enddocregion -->
{ "end_byte": 318, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/src/index.html" }
angular/adev/src/content/examples/i18n/src/main.ts_0_423
// #docregion global-locale import '@angular/common/locales/global/fr'; // #enddocregion global-locale import {provideProtractorTestingSupport} from '@angular/platform-browser'; import {bootstrapApplication} from '@angular/platform-browser'; import {AppComponent} from './app/app.component'; bootstrapApplication(AppComponent, { providers: [ provideProtractorTestingSupport(), // essential for e2e testing ], });
{ "end_byte": 423, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/src/main.ts" }
angular/adev/src/content/examples/i18n/src/locale/messages.fr.xlf_0_4828
<?xml version="1.0" encoding="UTF-8" ?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template"> <body> <trans-unit id="introductionHeader" datatype="html"> <source> Hello i18n! </source> <target> Bonjour i18n ! </target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">4</context> </context-group> <note priority="1" from="description">An introduction header for this sample</note> <note priority="1" from="meaning">User welcome</note> </trans-unit> <trans-unit id="5206857922697139278" datatype="html"> <source>I don&apos;t output any element</source> <target>Je n'affiche aucun élément</target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">10</context> </context-group> </trans-unit> <trans-unit id="392942015236586892" datatype="html"> <source>Angular logo</source> <target>Logo d'Angular</target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">16</context> </context-group> </trans-unit> <trans-unit id="4606963464835766483" datatype="html"> <source>Updated <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source> <target>Mis à jour <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">21</context> </context-group> </trans-unit> <trans-unit id="2002272803511843863" datatype="html"> <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago} }</source> <target>{VAR_PLURAL, plural, =0 {à l'instant} =1 {il y a une minute} other {il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes} }</target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">21</context> </context-group> </trans-unit> <trans-unit id="3560311772637911677" datatype="html"> <source>The author is <x id="ICU" equiv-text="{gender, select, male {...} female {...} other {...}}"/></source> <target>L'auteur est <x id="ICU" equiv-text="{gender, select, male {...} female {...} other {...}}"/></target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">27</context> </context-group> </trans-unit> <trans-unit id="7670372064920373295" datatype="html"> <source>{VAR_SELECT, select, male {male} female {female} other {other} }</source> <target>{VAR_SELECT, select, male {un homme} female {une femme} other {autre} }</target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">27</context> </context-group> </trans-unit> <trans-unit id="3967965900462880190" datatype="html"> <source>Updated: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/> </source> <target>Mis à jour: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/> </target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">31</context> </context-group> </trans-unit> <trans-unit id="2508975984005233379" datatype="html"> <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago by {VAR_SELECT, select, male {male} female {female} other {other} }} }</source> <target>{VAR_PLURAL, plural, =0 {à l'instant} =1 {il y a une minute} other {il y a <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes par {VAR_SELECT, select, male {un homme} female {une femme} other {autre} }} }</target> <context-group purpose="location"> <context context-type="sourcefile">app\app.component.ts</context> <context context-type="linenumber">31</context> </context-group> </trans-unit> </body> </file> </xliff>
{ "end_byte": 4828, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/src/locale/messages.fr.xlf" }
angular/adev/src/content/examples/i18n/src/locale/messages.xlf_0_3849
<?xml version="1.0" encoding="UTF-8" ?> <xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2"> <file source-language="en" datatype="plaintext" original="ng2.template"> <body> <trans-unit id="introductionHeader" datatype="html"> <source> Hello i18n! </source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">3</context> </context-group> <note priority="1" from="description">An introduction header for this sample</note> <note priority="1" from="meaning">User welcome</note> </trans-unit> <trans-unit id="5206857922697139278" datatype="html"> <source>I don&apos;t output any element</source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">9</context> </context-group> </trans-unit> <trans-unit id="392942015236586892" datatype="html"> <source>Angular logo</source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">15</context> </context-group> </trans-unit> <trans-unit id="4606963464835766483" datatype="html"> <source>Updated <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">20</context> </context-group> </trans-unit> <trans-unit id="2002272803511843863" datatype="html"> <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago} }</source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">20</context> </context-group> </trans-unit> <trans-unit id="3560311772637911677" datatype="html"> <source>The author is <x id="ICU" equiv-text="{gender, select, male {...} female {...} other {...}}"/></source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">26</context> </context-group> </trans-unit> <trans-unit id="7670372064920373295" datatype="html"> <source>{VAR_SELECT, select, male {male} female {female} other {other} }</source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">26</context> </context-group> </trans-unit> <trans-unit id="3967965900462880190" datatype="html"> <source>Updated: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/> </source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">30</context> </context-group> </trans-unit> <trans-unit id="2508975984005233379" datatype="html"> <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago by {VAR_SELECT, select, male {male} female {female} other {other} }} }</source> <context-group purpose="location"> <context context-type="sourcefile">app/app.component.ts</context> <context context-type="linenumber">30</context> </context-group> </trans-unit> </body> </file> </xliff>
{ "end_byte": 3849, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/src/locale/messages.xlf" }
angular/adev/src/content/examples/i18n/src/app/app.component.html_0_1522
<!--#docregion--> <h1 i18n="User welcome|An introduction header for this sample@@introductionHeader"> Hello i18n! </h1> <!--#docregion i18n-ng-container--> <ng-container i18n>I don't output any element</ng-container> <!--#enddocregion i18n-ng-container--> <br /> <!--#docregion i18n-title-translate--> <img [src]="logo" i18n-title title="Angular logo" alt="Angular logo"/> <!--#enddocregion i18n-title-translate--> <br> <button type="button" (click)="inc(1)">+</button> <button type="button" (click)="inc(-1)">-</button> <!--#docregion i18n-plural--> <span i18n>Updated {minutes, plural, =0 {just now} =1 {one minute ago} other {{{ minutes }} minutes ago}}</span> <!--#enddocregion i18n-plural--> ({{ minutes }}) <br><br> <button type="button" (click)="male()">&#9794;</button> <button type="button" (click)="female()">&#9792;</button> <button type="button" (click)="other()">&#9895;</button> <!--#docregion i18n-select--> <span i18n>The author is {gender, select, male {male} female {female} other {other}}</span> <!--#enddocregion i18n-select--> <br><br> <!--#docregion i18n-nested--> <span i18n>Updated: {minutes, plural, =0 {just now} =1 {one minute ago} other {{{ minutes }} minutes ago by {gender, select, male {male} female {female} other {other}}}} </span> <!--#enddocregion i18n-nested--> <br><br> <!--#docregion i18n-conditional--> <button type="button" (click)="toggleDisplay()">Toggle</button> <div i18n [attr.aria-label]="toggleAriaLabel()">{{toggle()}}</div> <!--#enddocregion i18n-conditional-->
{ "end_byte": 1522, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/src/app/app.component.html" }
angular/adev/src/content/examples/i18n/src/app/app.component.ts_0_853
// #docregion import {Component, computed, signal} from '@angular/core'; import {$localize} from '@angular/localize/init'; @Component({ standalone: true, selector: 'app-root', templateUrl: './app.component.html', }) export class AppComponent { minutes = 0; gender = 'female'; fly = true; logo = '${this.baseUrl}/angular.svg'; toggle = signal(false); toggleAriaLabel = computed(() => { return this.toggle() ? $localize`:Toggle Button|A button to toggle status:Show` : $localize`:Toggle Button|A button to toggle status:Hide`; }); inc(i: number) { this.minutes = Math.min(5, Math.max(0, this.minutes + i)); } male() { this.gender = 'male'; } female() { this.gender = 'female'; } other() { this.gender = 'other'; } toggleDisplay() { this.toggle.update((toggle) => !toggle); } }
{ "end_byte": 853, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/i18n/src/app/app.component.ts" }
angular/adev/src/content/examples/accessibility/BUILD.bazel_0_181
package(default_visibility = ["//visibility:public"]) exports_files([ "src/app/app.component.html", "src/app/app.component.ts", "src/app/progress-bar.component.ts", ])
{ "end_byte": 181, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/BUILD.bazel" }
angular/adev/src/content/examples/accessibility/e2e/src/app.e2e-spec.ts_0_603
import {browser, element, by} from 'protractor'; describe('Accessibility example e2e tests', () => { beforeEach(() => browser.get('')); it('should display Accessibility Example', async () => { expect(await element(by.css('h1')).getText()).toEqual('Accessibility Example'); }); it('should take a number and change progressbar width', async () => { await element(by.css('input')).sendKeys('16'); expect(await element(by.css('input')).getAttribute('value')).toEqual('16'); expect(await element(by.css('app-example-progressbar div')).getCssValue('width')).toBe('48px'); }); });
{ "end_byte": 603, "start_byte": 0, "url": "https://github.com/angular/angular/blob/main/adev/src/content/examples/accessibility/e2e/src/app.e2e-spec.ts" }