离子 4 中"Cannot read property 'displayName' of undefined"错误



我正在创建一个呼叫者名称扬声器应用程序。在Ionic 4中,我能够获得传入的呼叫者状态和号码。有了这个数字,我想在联系人名称中找到一个名称,在那里我面对问题。

首先,我执行了一个运行命令:离子Cordova运行Android在设备中运行该应用程序,然后使用Chrome Inspect检查应用程序,在Chrome Inspect中我遇到了此错误。

polyfills.js:3040 Unhandled Promise rejection: Cannot read property 'displayName' of undefined ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot read property 'displayName' of undefined
at home-home-module.js:275
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (polyfills.js:2749)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (polyfills.js:2508)
at polyfills.js:3247
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (polyfills.js:2781)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (polyfills.js:2553)
at drainMicroTaskQueue (polyfills.js:2959) TypeError: Cannot read property 'displayName' of undefined
at http://localhost/home-home-module.js:275:87
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (http://localhost/polyfills.js:2749:26)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.run (http://localhost/polyfills.js:2508:43)
at http://localhost/polyfills.js:3247:34
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost/polyfills.js:2781:31)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost/polyfills.js:2553:47)
at drainMicroTaskQueue (http://localhost/polyfills.js:2959:35)

在这里代码页。TS文件:

declare var window: any;
//phone calls
phonecalls() {
window.PhoneCallTrap.onCall((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
  let fields: ContactFieldType[] = ['displayName'];
  const options = new ContactFindOptions();
  options.filter = callingNumber;
  options.multiple = true;
  options.hasPhoneNumber = true;
  this.contact.find(fields, options).then((contacts) => {
    this.contactsfoundcallingNumber = contacts;
    console.log("contactsfound call", this.contactsfoundcallingNumber[0].displayName);
    console.log(JSON.stringify(contacts[0].displayName));
  });
  console.log("Hell lvl2: " + 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;
  }
});
}

帮助,请...

基于您的代码,我将登录Console Contacts对象,以查看其具有多少元素以及这些元素中显示名的值是什么。

最新更新