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);
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • NAME dnsmasq - A lightweight DHCP and caching DNS server....
    ximitc閱讀 2,993評(píng)論 0 0
  • 兩大碗涼面條下肚,頓感撐的慌。就出去走了一遭,回家懶床擺鼓手機(jī)。 打開(kāi)簡(jiǎn)書(shū),看了別人寫(xiě)的東西,突然,沒(méi)有了自信。咱...
    日光浴的男子閱讀 224評(píng)論 1 0
  • 你花多少時(shí)間去修正果,果就有多正。 所有的付出都是有回報(bào)的,我們唯一要做的就是調(diào)整心態(tài),修心,修因果,修自我。 晚...
    馨動(dòng)小v姐閱讀 182評(píng)論 0 0
  • 《這件事情不重視,孩子的皮膚和眼睛都?xì)Я恕贩椒? 《孩子獲得美國(guó)國(guó)籍有什么好處》方法2 《行車(chē)儀器有什么好處?》方...
    直徑文摘閱讀 249評(píng)論 0 0

友情鏈接更多精彩內(nèi)容