0
我得到我的离子2应用程序中的错误与角2,第一本错误错误:未捕获的(在承诺):类型错误:无法读取的不确定离子2
runtime error Cannot read property 'name' of undefined
其次这个属性“名”
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'name' of undefined
最后这个
ERROR CONTEXT DebugContext_ {view: Object, nodeIndex: 14, nodeDef: Object, elDef: Object, elView: Object}
一些时间顺序改变,但所有的错误都来了。
代码
@Component({
selector: 'page-details',
templateUrl: 'details.html',
})
export class DetailsPage {
id: any;
public dataObj: any;
public Records: any
constructor(public navCtrl: NavController, public navParams: NavParams, public absService: AbsconderService, public posService: PosService) {
this.id = navParams.get('id');
console.log('constructor');
this.getData(this.id)
}
getData(id) {
console.log('service called');
this.absService.getAbsconderById(id)
.then(data => {
this.Records = data;
this.dataObj = {
name : this.Records.data[0].name,
nic : this.Records.data[0].nic,
fname: this.Records.data[0].fname,
caste: this.Records.data[0].caste,
residence: this.Records.data[0].residence,
crime_no: this.Records.data[0].crime_no,
us: this.Records.data[0].us,
ps: this.Records.data[0].ps
}
console.log(this.dataObj);
})
};
ionViewDidLoad() {
console.log('ionViewDidLoad Details');
}
}
模板
<ion-content padding>
<ion-item>
<ion-label stacked>Name</ion-label>
<ion-label>{{dataObj.name}}</ion-label>
</ion-item>
<ion-item>
<ion-label stacked>NIC No.</ion-label>
<ion-label>{{dataObj}}</ion-label>
</ion-item>
</ion-content>
通过把?处理。 – Mangrio
放?解决了我的问题。我们可以从.js文件处理这个吗? – Mangrio