【发布时间】:2018-05-26 14:59:32
【问题描述】:
我在 Hero 模型的 id 和 name 旁边添加了 description 属性 hero.ts:
export class Hero{
id: number;
name: string;
description: string;
}
现在在教程的 HTTP 部分,我正在尝试使用他们在教程中提供的功能添加一个新英雄:
src/app/heroes/heroes.component.html(添加):
<div>
<label>Hero name:
<input #heroName />
</label>
<!-- (click) passes input value to add() and then clears the input -->
<button (click)="add(heroName.value); heroName.value=''">
add
</button>
</div>
src/app/heroes/heroes.component.ts(添加):
add(name: string): void {
name = name.trim();
if (!name) { return; }
this.heroService.addHero({ name } as Hero)
.subscribe(hero => {
this.heroes.push(hero);
});
}
src/app/hero.service.ts (addHero):
/** POST: add a new hero to the server */
addHero (hero: Hero): Observable<Hero> {
return this.http.post<Hero>(this.heroesUrl, hero, httpOptions);
}
enter code here
我应该在哪个功能中添加什么才能推送英雄描述?
【问题讨论】:
标签: angular