Using console.log() with Angular

From: https://stackoverflow.com/questions/37869496/console-log-not-working-in-angular2-component-typescript
Author: Daniel Pliscki

It's not working because console.log() it's not in a "executable area" of the class "App".

A class is a structure composed by attributes and methods.

The only way to have your code executed it's to place it inside a method that is going to be executed. For instance: constructor() or ngOnInit()

console.log('It works here')

@Component implements OnInit({..)
export class App {
  s: string = "Hello";
            
  constructor() {
    console.log(this.s)            
  }

  ngOnInit(){
    console.log(123);
  }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc阅读 3,020评论 0 0
  • 两大碗凉面条下肚,顿感撑的慌。就出去走了一遭,回家懒床摆鼓手机。 打开简书,看了别人写的东西,突然,没有了自信。咱...
    日光浴的男子阅读 229评论 1 0
  • 你花多少时间去修正果,果就有多正。 所有的付出都是有回报的,我们唯一要做的就是调整心态,修心,修因果,修自我。 晚...
    馨动小v姐阅读 185评论 0 0
  • 《这件事情不重视,孩子的皮肤和眼睛都毁了》方法1 《孩子获得美国国籍有什么好处》方法2 《行车仪器有什么好处?》方...
    直径文摘阅读 253评论 0 0

友情链接更多精彩内容