2017-10-05 72 views
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的值,这是行不通的。我已经尝试了一切。这里可能是什么问题?有没有人有过同样的问题?

在此先感谢!

+0

错字,应该是'string' for testVariable –

+1

删除“this”。从变量(也是Queintin说的),你应该发布你的错误信息,虽然 – Laurens

+0

感谢您的回答,伙计们! @q – Thisisalexis

回答

0

我找到了解决方案。这听起来可能很愚蠢,很明显,但我想这对于Angular和Web开发新手来说可能会有所帮助。

我的组件还行!但在JS控制台中,我可以看到另一个组件出现错误。解决这个问题(在另一个组件中)我的应用程序开始正常工作。

我在这里学到的是一个组件中的错误,可能使其他组件和功能无法正常工作。感谢那些回答问题的人。