错误是离子4中的“无法读取null的属性'contact'”

时间:2019-04-29 09:49:10

标签: angular ionic-framework ionic4

我要在ionic 4中创建一个呼叫者姓名扬声器应用程序。为此,我能够获取来电者状态和号码。我想用这个号码在联系人中找到一个名字。

此处代码:

phonecalls() {
PhoneCallTrap.onCall(function (obj) {
  alert("CHANGE STATE: " + obj.state);
  var callObj = JSON.parse(obj),
    state = callObj.state,
    callingNumber = callObj.incomingNumber;
  console.log("obj: " + obj);

  //working
  alert("callingNumber STATE: " + callingNumber);

  //call name get
  const options = new ContactFindOptions();
  options.filter = callingNumber;
  options.multiple = true;
  options.hasPhoneNumber = true;
  this.contact.find(['*'], options).then((contacts) => {
    this.contactsfoundcallingNumber = contacts[0].displayName;
    console.log(JSON.stringify(contacts[0]));
  });

  alert("well well: " + this.contactsfoundcallingNumber)

  switch (state) {
    case "RINGING":
      console.log("Phone is ringing", callingNumber);
      break;
    case "OFFHOOK":
      console.log("Phone is off-hook");
      break;
    case "IDLE":
      console.log("Phone is idle");
      break;
  }
});
}

此处chrome使用USB调试进行检查

enter image description here

1 个答案:

答案 0 :(得分:2)

将回调函数更改为Arrow函数,将保留[Authorization(role)]引用。

this