0
我有角2一个组件,它看起来像这样:角2:属性的组件值未在HTML显示(DOM))当我looad页面首次
@Component({
selector: 'gal-tour-summary',
template: 'Show variable: {{this.testVariable}}',
styleUrls: ['./tour-summary.component.css']
})
export class TourSummaryComponent implements OnInit {
cruise: any;
itineraries: any;
testVariable: string; //This is the variable i have created
constructor(private utils: UtilsService) {
\t testVariable = "Why this text does not appearr in my page when the component is loaded??"; //Here, in the constructo, I put some value to my variable, so, it should appear in my html now, right?
}
ngOnInit() {
this.cruise = this.utils.linked['selectedBarco'];
this.itineraries = this.createIterDay(this.cruise.itinerarios[this.cruise.iterIndex].tipoItinerario.detalleItinerarioList);
console.log('Total de itinerarios: ' + this.itineraries.length);
}
}
问题是,我试图在HTML中显示testVariable的值,这是行不通的。我已经尝试了一切。这里可能是什么问题?有没有人有过同样的问题?
在此先感谢!
错字,应该是'string' for testVariable –
删除“this”。从变量(也是Queintin说的),你应该发布你的错误信息,虽然 – Laurens
感谢您的回答,伙计们! @q – Thisisalexis