angular 2 template use console.log

前端 未结 3 449
滥情空心
滥情空心 2021-02-01 13:16

I would like to use the console.log inside the inline template but can\'t find any directions.

@Component({
  selector:\"main\",
  providers: [ItemService],
  te         


        
3条回答
  •  时光取名叫无心
    2021-02-01 13:41

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

提交回复
热议问题