2. 一个简单的英雄编辑器

步骤一:

1. AppComponent添加2个属性,title,hero

{

title = '英雄联盟';

hero = '李白';

}

2.在app.component.html当中就可以使用{{title}},{{hero}},输出内容

步骤二:

声明一个Hero类

export class Hero{
id: number;

name: string;

}

AppComponent中hero属性更改如下

hero: Hero = {

id: 1,

name: '李白'

}

app.component.html 当中改成 {{hero.name}}

3.input表单绑定 [(ngModel)] = "hero.name"

新建<input [(ngModel)]="hero.name" placeholder="name" />

原文地址:https://www.cnblogs.com/hanweb/p/6740857.html