how to bind a constant to target component in angular2(dart)?


I’m following the tutorial here:

So I thought it would be possible to bind multiple targets:


<my-hero-detail [hero]="selectedHero" [msg]="123"></my-hero-detail>


    selector: 'my-hero-detail',
    template: '''
      <div *ngIf="hero != null">
        <h2>{{msg}} {{}} details!</h2>
        <div><label>id: </label>{{}}</div>
          <label>name: </label>
          <input [(ngModel)]="" placeholder="name">
class HeroDetailComponent {
    Hero hero;

    String msg;

So I noticed something obviously wrong. Angular needs to distinguish between a property of the AppComponent (selectedHero in this case) and realize that 123 is not a variable, but a value I want to assign to msg property.

So the question is — how can we pass a value to HeroDetailComponent?


If I understood you correctly, you want to assign value 123 to msg property, not value of variable named 123. There are two ways to do this:

<my-hero-detail [hero]="selectedHero" msg="123"></my-hero-detail> //first way

<my-hero-detail [hero]="selectedHero" [msg]="'123'"></my-hero-detail> //second way

Answered By – Stefan Svrkota

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *