Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 错误是;无法读取属性';显示名称';“未定义”的定义;在离子4中_Angular_Ionic Framework_Ionic4 - Fatal编程技术网

Angular 错误是;无法读取属性';显示名称';“未定义”的定义;在离子4中

Angular 错误是;无法读取属性';显示名称';“未定义”的定义;在离子4中,angular,ionic-framework,ionic4,Angular,Ionic Framework,Ionic4,我正在离子4中创建呼叫者姓名扬声器应用程序。为此,我可以得到来电状态和号码。有了这个号码,我想在联系人姓名中找到一个姓名,我就面临着这个问题 首先,我执行了一个run命令:ionic Cordova运行android在设备中运行应用程序,然后使用chrome inspect检查应用程序,在chrome inspect中我得到了这个错误 polyfills.js:3040 Unhandled Promise rejection: Cannot read property 'displayName'

我正在离子4中创建呼叫者姓名扬声器应用程序。为此,我可以得到来电状态和号码。有了这个号码,我想在联系人姓名中找到一个姓名,我就面临着这个问题

首先,我执行了一个run命令:ionic 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)

帮助,请…

根据您的代码,我将登录到console contacts对象,查看它有多少个元素,以及这些元素中displayName的值是多少

this.contact.find
从哪里来?您在
中有什么信息。请联系
?问题似乎就在这个函数里面。你需要提供额外的代码,如果你添加一个stackblitz示例将非常有帮助。我只有这个代码,没有其他代码,你可以在这里检查这个家伙做了一些有趣的事情,我们可以用他的代码搜索:这个示例中的家伙可能有
这个。联系
声明。在stackblitz中做一个实例,这样我们可以帮助您,因为我们需要知道对象的值。可能他在构造函数中有私人联系人:联系人,从
@ionic native/contacts/ngx
导入。是的,我正在使用ionic联系人插件,并导入到app.module.ts和hope.page.ts文件中。嗯,我发现了一个问题。打进来的电话,我得到的号码带有国家代码,而save contact number没有国家代码,这就是为什么我得不到国家代码这不是答案否,但它可以帮助找到答案。也许我应该把它改成一个注释…那么,联系人对象是空的吗?如果是这样,那么displayName是未定义的,如错误所示。不幸的是,我不知道为什么它是空的。您可以在代码callingNumber(找到的号码)中看到,然后我在联系人筛选器中添加了callingNumber
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;
  }
});
}