[英]how to bind a constant to target component in angular2(dart)?
我正在關注這里的教程: https : //angular.io/docs/dart/latest/tutorial/toh-pt3.html
所以我認為可以綁定多個目標:
應用組件.dart
<my-hero-detail [hero]="selectedHero" [msg]="123"></my-hero-detail>
hero_detail_component.dart
@Component(
selector: 'my-hero-detail',
template: '''
<div *ngIf="hero != null">
<h2>{{msg}} {{hero.name}} details!</h2>
<div><label>id: </label>{{hero.id}}</div>
<div>
<label>name: </label>
<input [(ngModel)]="hero.name" placeholder="name">
</div>
</div>'''
)
class HeroDetailComponent {
@Input()
Hero hero;
@Input()
String msg;
}
所以我注意到一些明顯的錯誤。 Angular 需要區分AppComponent
一個屬性(本例中為selectedHero
)並意識到123
不是一個變量,而是一個我想分配給msg
屬性的值。
所以問題是——我們如何將值傳遞給HeroDetailComponent
?
如果我理解正確,您想將值123
分配給msg
屬性,而不是名為123
的變量的值。 有兩種方法可以做到這一點:
<my-hero-detail [hero]="selectedHero" msg="123"></my-hero-detail> //first way
<my-hero-detail [hero]="selectedHero" [msg]="'123'"></my-hero-detail> //second way
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.