2

I'm following the tutorial here: https://angular.io/docs/dart/latest/tutorial/toh-pt3.html

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

app-component.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;
}

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?

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.