我正在使用Ionic 2框架,尝试使用php从本地主机检索数据,并在应用程序上显示。我能够从我的第一页(listingPage)获取数据库中的数据,但是,当涉及第二页(StoreInfoPage)时,我收到错误:没有值名称的表单控件访问器。我不确定哪个部分我做错了。
另外,我只计划显示数据,不应该有任何更新/删除/插入。我不确定我是否以正确的方式做到这一点,感谢您给予的任何帮助和建议。
listing.html
<ion-item *ngFor="let listing of listings">
<ion-avatar item-start>
<img height="60" width="60" src="xxx.jpg">
</ion-avatar>
<h2 class="payment_color">{{ listing.ListingTitle }}</h2>
<p>{{ listing.ListingDate }} {{ listing.ListingTime }}</p>
<ion-note item-end>
<p><button (click)="viewEntry({ record: listing })" ion-button color="danger">Apply</button></p>
</ion-note>
</ion-item>
listing.ts
import { Component } from '@angular/core';
import { NavController,ModalController } from 'ionic-angular';
import { ActionSheetController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'page-list',
templateUrl: 'listview.html'
})
export class ListPage {
public listings : any = [];
constructor(public navCtrl: NavController,
public actionSheetCtrlCat: ActionSheetController,
public actionSheetCtrljob_type: ActionSheetController,
public actionSheetCtrlLoc: ActionSheetController,
public actionSheetCtrlSal: ActionSheetController,
public modalCtrl: ModalController,
public http: Http
){}
ionViewWillEnter(){
this.load();
}
load()
{
this.http.get('http://localhost/php-mysql/retrieve-
data.php')
.map(res => res.json())
.subscribe(data =>
{
this.listings = data;
});
}
viewEntry(param)
{
this.navCtrl.push('StoreInfoPage', param);
}
storeInfo.html
<ion-row>
<ion-card>
<img src="xxx.jpg">
<div class="card-title">xxx</div>
<div class="card-subtitle">xxx</div>
</ion-card>
</ion-row>
<ion-row>
<ion-col col-12 text-center >
<p formControlName="ListingDate" [(ngModel)]="ListingDate"> xxx</p>
<p>xxx</p>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-12>
<h6>xxx</h6>
<p> xxx</p>
</ion-col>
</ion-row>
<div text-center>
<button fab-center ion-button color="primary"
(click)="applyAlert()">
Apply
</button>
</div>
</form>
storeInfo.ts
import { Component } from '@angular/core';
import { IonicPage, NavController,
NavParams,ViewController,AlertController,ToastController } from '
ionic-angular';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map';
import { FormGroup, Validators, FormBuilder } from '@angular/forms';
@IonicPage()
@Component({
selector: 'page-store-info',
templateUrl: 'store-info.html',
})
export class StoreInfoPage {
public ListingDate : any;
public form : FormGroup;
constructor(public navCtrl: NavController,
public navParams : NavParams,
public viewCtrl : ViewController,
public alertCtrl : AlertController,
public http : Http,
public NP : NavParams,
public fb : FormBuilder,
) {
this.form = fb.group({
"ListingDate" : ["", Validators.required],
});
}
ionViewWillEnter()
{
this.NP.get("record");
}
selectEntry(listing)
{
this.ListingDate = listing.ListingDate;
}
}
答案 0 :(得分:2)
我想你的问题就在 storeInfo.html :
中<p formControlName="ListingDate" [(ngModel)]="ListingDate"> xxx</p>
查看documentation是否正确使用。 您应该将此formControlName用于表单中的输入。