[英]Angular2 - Two-way data binding issue
我必須單擊一個顯示城市列表的div,當我單擊顯示的城市之一時,我想執行一個方法並顯示cityName,因為到目前為止我的工具是這樣的:
文件1的HTML
<div [(ngModel)]="cityName" class="heads">{{cityName}}</div>
文件1的.js
@Injectable()
export class queryToDB {
constructor(http) {
this.http = http;
this.valueToBeChanged = "Select a city";
}
}
文件2 :
@Component({
template: `
<div>
<button ion-item *ngFor="let city of cities" (click)="switchToThisCity(city.cityName);">{{city.cityName | uppercase}}</button>
</div>
`,
providers:[queryToDB]
})
export class MyPopover{
static get parameters(){
return [[Http]];
}
constructor(http) {
this.http = http;
}
switchToThisCity(currentCity){
this.cityName = "New York";
}
}
但是,我收到以下錯誤:
例外:“”沒有值訪問器
關於導致問題的原因有什么想法?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.