0

I have narrowed down the problem I'm having to this directive code:

@Directive({
  selector: '[tdStepTracker]'
})
export class StepTrackerDirective {
  @Input('tdStepTracker') keyName: string;

  ngOnInit() {
    console.log('keyName', this.keyName);
  }
}

And being used here:

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2 [tdStepTracker]="something">Hello {{name}}</h2>
    </div>
  `,
})
export class App {
  name:string;
  constructor() {
    this.name = 'Angular2'
  }
}

When I log the contents of this.keyName I get undefined. I was expecting to get something instead.

Here's a link to the plunker: https://plnkr.co/edit/Cbw6CHbsppiuVpW4kpTh

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
kolrie
  • 12,562
  • 14
  • 64
  • 98

1 Answers1

2

Seems you want to pass a string

<h2 [tdStepTracker]="something">Hello {{name}}</h2>

should be changed to one of

<h2 [tdStepTracker]="'something'">Hello {{name}}</h2>
<h2 tdStepTracker="something">Hello {{name}}</h2>

Your code binds to a property something of class App which doesn't exist.

Plunker example

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567