首页 > 解决方案 > 无法在函数中设置未定义离子的属性

问题描述

错误:无法在要使用的函数中设置未定义的属性 x2

  x2 : string;
  const provider = new OpenStreetMapProvider();
  const results = provider.search({query : this.city}).then( function(e){
    console.log("function(e)",e[0]);
    this.x2=e[0].x;
  });

标签: ionic3

解决方案


好的

x2 : string;
const provider = new OpenStreetMapProvider();
const results = provider.search({query : this.city}));

results.then( (e) => {
  console.log("function(e)",e[0]);
  this.x2=e[0].x;
}

推荐阅读