我有以下代碼:Angular2構造沒有運行
// Imports
import { Component } from '@angular/core';
@Component({
templateUrl: './app/my.component.html'
})
export class MyComponent{
s: string = "Test";
constructor() {
console.log(this.s)
}
}
後,我跑我的應用程序的console.log不顯示「測試」文本。我做錯了什麼?
組件在哪裏被加載? –
我在app.module –
中加載組件您是否路由到它?你的代碼沒有問題,如果組件在你的應用程序中顯示,它將顯示console.log()。 –