Issue
I would like to use the console.log inside the inline template but can't find any directions.
@Component({
selector:"main",
providers: [ItemService],
template:`
<ul>
<li *ngFor="let item of items">
{{console.log(item)}} <----- ???
<p>{{item.name}}</p>
</li>
</ul>
`
})
export class HomeComponent {
private items: Array<ItemModel>;
constructor() {}
}
Solution
You can't access globals, statics, ...
You can only access properties of the component the view belongs to.
You can add a
log(val) { console.log(val); }
to your component and use it like
{{log(item)}}
but be prepared this to be logged quite often (every time change detection runs).
For debugging I prefer
{{item | json}}
Answered By - Günter Zöchbauer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.