angular 2 template use console.log

Better way to do it :

This way you can access all the console properties on template side


Component side :

export class AppComponent  {
  console = console;
}

Template Side :

{{ console.log('----------------> Logging') }}
{{ console.warn('----------------> Warning') }}
{{ console.error('----------------> error') }}

WORKING DEMO


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}} 

Tags:

Angular