Tuesday, August 09, 2016

Angular 2 - template reference variable shadows the component property

Given the Angular 2 component:

import { Component } from '@angular/core';

  moduleId: module.id,
  selector: 'app-root',
  template: '<div ref-title>{{title}}</div>',
  styleUrls: ['app.component.css']
export class AppComponent {
  title =  'app works!';

you get this on the webpage:

[object HTMLDivElement]

The reason is that Template Reference Variable ref-title shadows the title of  AppComponent when evaluating {{title}}.

I guess this is sort of like the loop variables inside an

<li *ngFor="let title in titles">{{title}}</li>

But something does not feel right about TRV.

No comments: