mirror of
https://github.com/angular/angular.git
synced 2026-12-06 13:19:15 -05:00
Supplements PR 51364 Template Migration with overlooked pages and examples Code migrated: `inputs-outputs`, `interpolation`, `property-binding` Guide pages affected: * `binding-overview.md` * `event-binding.md` (already migrated; updated with link to explain passive events) * `inputs-outputs.md` * `interpolation.md` * `property-binding-best-practices.md` * `property-binding.md` * `understanding-template-expr-overview.md` (archived) E2E tests passed locally. PR Close #51632
40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
/* eslint-disable @angular-eslint/no-input-rename,
|
|
@angular-eslint/no-inputs-metadata-property,
|
|
@angular-eslint/no-output-rename,
|
|
@angular-eslint/no-outputs-metadata-property */
|
|
import { Component, EventEmitter, Input, Output } from '@angular/core';
|
|
|
|
@Component({
|
|
standalone: true,
|
|
selector: 'app-aliasing',
|
|
template: `
|
|
<p>Save for later item: {{input1}}</p>
|
|
<button type="button" (click)="saveIt()"> Save for later</button>
|
|
|
|
<p>Item for wishlist: {{input2}}</p>
|
|
<button type="button" (click)="wishForIt()"> Add to wishlist</button>
|
|
`,
|
|
inputs: ['input1: saveForLaterItem'], // propertyName:alias
|
|
outputs: ['outputEvent1: saveForLaterEvent']
|
|
})
|
|
export class AliasingComponent {
|
|
|
|
input1 = '';
|
|
outputEvent1: EventEmitter<string> = new EventEmitter<string>();
|
|
|
|
@Input('wishListItem') input2 = ''; // @Input(alias)
|
|
@Output('wishEvent') outputEvent2 = new EventEmitter<string>(); // @Output(alias) propertyName = ...
|
|
|
|
|
|
saveIt() {
|
|
console.warn('Child says: emitting outputEvent1 with', this.input1);
|
|
this.outputEvent1.emit(this.input1);
|
|
}
|
|
|
|
wishForIt() {
|
|
console.warn('Child says: emitting outputEvent2', this.input2);
|
|
this.outputEvent2.emit(this.input2);
|
|
}
|
|
|
|
}
|