영웅을 화면에 나타내기 위해 영웅클래스를 만들어준다.
-------app.component.js----------
>>@Component 의 templatedp 작성할 내용들을 적어준다.
@Component({
//루트 컴포넌트이다.
selector: 'app-root',
//templateUrl: './app.component.html',
template: `
<h1>{{ title }}</h1> // export class의 title사용
<h2>{{ hero.name }}</h2> //히어로 라는 클래스의 name을 사용 ( ngModel로 바인딩 되어있음
<div><label>id: </label>{{ hero.id }}</div>
<div>
<label> 이름 : </label>
//아래와 같이 모델링 해준다.
<input [(ngModel)]="hero.name" placeholder="이름" />
</div>
`,
styleUrls: ['./app.component.css'],
})
[(ngModel)]을 사용하기 위해서는 app.module.ts 에
import { FormsModule } from '@angular/forms';
@NgModule{
. . .
imports: [BrowserModule, AppRoutingModule, FormsModule],
. . .
} 위와 같이 추가.
'Angular.js' 카테고리의 다른 글
*ngFor , *ngIf , (click)="func(Hero)" (0) | 2020.07.06 |
---|---|
ts 파일에서 : 와 = 차이점 (0) | 2020.07.06 |
새로운 컴포넌트 등록 및 데이터 바인딩 (0) | 2020.07.06 |
Angular Cli 으로 프로젝트 시작 (0) | 2020.07.06 |
TypeScript in VS_Code (0) | 2020.07.06 |