美文网首页
Using console.log() with Angular

Using console.log() with Angular

作者: RoyTien | 来源:发表于2017-06-28 09:18 被阅读15次

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

    相关文章

      网友评论

          本文标题:Using console.log() with Angular

          本文链接:https://www.haomeiwen.com/subject/ftnycxtx.html