ヒーローを追加した後、空の文字列に値をリセットしたいという簡単な入力があります。問題は値が更新されていないことです。どうして?リセット後に角2の入力値が更新されない
@Component({
selector: 'my-app',
template: `
<input type="text" [value]="name" #heroname />
<button (click)="addHero(heroname.value)">Add Hero!</button>
<ul>
<li *ngFor="let hero of heroes">
{{ hero.name }}
</li>
</ul>
`,
})
export class App {
name: string = '';
heroes = [];
addHero(name: string) {
this.heroes.push({name});
// After this code runs I expected the input to be empty
this.name = '';
}
}
プッシュ({name})、プッシュ(name)だけでなく、({name:name})をプッシュするのはなぜですか? – knobo