无法读取未定义的 属性 'create'
cannot read property 'create' of undefined
在 ionic3 页面中,我想通过单击事件的函数打开模式
export class HomePage {
....
....
....
loadPos() {
var randomLocations = Microsoft.Maps.TestDataGenerator.getLocations(5, this.map.getBounds());
for (let i = 0; i < 5; i++) {
var pin = new Microsoft.Maps.Pushpin(randomLocations[i]);
this.map.entities.push(pin);
//Add a click event handler to the pushpin.
Microsoft.Maps.Events.addHandler(pin, 'click', this.pushpinClicked);
}
console.log("pins added")
pushpinClicked(e) {
HomePage.prototype.openModal()
}
openModal() {
const myModal = this.modal.create(ModalPage)
myModal.present()
}
}
当我 运行 来自 ionic-buttun 的 openModal() 函数时它工作但是当我 运行 来自图钉点击事件的函数时我得到了这个错误:
cannot read property 'create' of undefined
如何从点击事件中打开该模式?
什么
你只需要改变
pushpinClicked(e) {
HomePage.prototype.openModal()
}
到
pushpinClicked(e) {
this.openModal()
}
原因是 this.modal
等字段不在原型对象中。您可以在此处查看示例:https://stackblitz.com/edit/angular-i7wwfb 运行 并检查控制台以查看差异。
在 ionic3 页面中,我想通过单击事件的函数打开模式
export class HomePage {
....
....
....
loadPos() {
var randomLocations = Microsoft.Maps.TestDataGenerator.getLocations(5, this.map.getBounds());
for (let i = 0; i < 5; i++) {
var pin = new Microsoft.Maps.Pushpin(randomLocations[i]);
this.map.entities.push(pin);
//Add a click event handler to the pushpin.
Microsoft.Maps.Events.addHandler(pin, 'click', this.pushpinClicked);
}
console.log("pins added")
pushpinClicked(e) {
HomePage.prototype.openModal()
}
openModal() {
const myModal = this.modal.create(ModalPage)
myModal.present()
}
}
当我 运行 来自 ionic-buttun 的 openModal() 函数时它工作但是当我 运行 来自图钉点击事件的函数时我得到了这个错误:
cannot read property 'create' of undefined
如何从点击事件中打开该模式? 什么
你只需要改变
pushpinClicked(e) {
HomePage.prototype.openModal()
}
到
pushpinClicked(e) {
this.openModal()
}
原因是 this.modal
等字段不在原型对象中。您可以在此处查看示例:https://stackblitz.com/edit/angular-i7wwfb 运行 并检查控制台以查看差异。