【发布时间】:2018-03-17 05:15:54
【问题描述】:
我在 Angular 2 中有一个如下所示的组件:
@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) {
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 的值,但这不起作用。我已经尝试了一切。这里可能是什么问题?你们之前有没有人遇到过同样的问题?
提前致谢!
【问题讨论】:
-
错别字,testVariable应该是
string -
删除“这个”。从变量(也是Queintin所说的),你应该发布你的错误信息
-
感谢您的回答,伙计们! @q
-
嗨,@QuentinLaillé。那个错字只出现在我在这里输入的示例中,但在我的代码中写得很好。对于那个很抱歉。我可以解决这个问题,它不在这个组件中,而是在另一个我可以在控制台中看到的错误中,我猜这导致其他组件无法正常工作。我是 Angular 的新手,所以我不知道另一个组件中的错误(在提出这个问题之前我已经看到过)可能会导致其他功能或组件无法正常工作。感谢您的回复。
-
谢谢@Laurens!我可以解决这个问题,它不在这个组件中,而是在另一个我可以在控制台中看到的错误中,我猜这导致其他组件无法正常工作。我是 Angular 的新手,所以我不知道另一个组件中的错误可能会导致其他功能或组件无法正常工作。当您向我询问错误消息时,我告诉自己我应该首先解决该错误(在另一个组件中),以便我可以查看是否可以解决我的组件中的问题,就像这样。谢谢
标签: angular angular2-template angular-components