[英]data binding is not working in angular 4
這可能太基礎了,但是我還沒弄清楚。
我正在使用angular4。在“ app”文件夾中有一個名為Competitions的文件夾。
在這里,我有如下的Competitions-detail.component.ts文件:
import { Component } from '@angular/core'
@Component({
moduleId: module.id,
selector: 'competitions-detail',
templateUrl: 'competitions-detail.component.html',
styleUrls: [ 'competitions-detail.component.css' ]
})
export class CompetitionsDetailComponent {
title: 'Competencias';
}
然后我有我的模板文件:
<md-toolbar color="primary">
<md-icon>data_usage</md-icon>
<span><strong>LA M10</strong></span>
<span class="spacer"></span>
<span><strong>COMPETENCIAS</strong></span>
</md-toolbar>
<h1>COMPETENCIAS</h1>
<h1>{{title}}</h1>
<h2>COMPETENCIAS</h2>
<h2>{{title}}</h2>
這就是結果
如您所見,該模板運行良好,如果我對顯示的值進行硬編碼,甚至還有一些材料設計組件,但是由於某種原因,簡單的數據綁定{{}}不會顯示標題值。
我想念什么?
您正在分配類型,而不是實際設置字段:
title: string = 'Competencias';
使用方式,請確保字段title
只能具有字符串值: Compentencias
類不是對象。 應該是=而不是:
export class CompetitionsDetailComponent{
title = "Competencias";
}
嘗試
出口類CompetitionsDetailComponent {title ='Competencias'; }
代替
出口類CompetitionsDetailComponent {標題:'Competencias'; }
我認為變量賦值和聲明有問題。
title:字符串='Competencias'
變量賦值應為=而不是:
export class CompetitionsDetailComponent{
title = "Competencias";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.