我要在ionic 4中创建一个呼叫者姓名扬声器应用程序。为此,我能够获取来电者状态和号码。有了这个号码,我想在联系人姓名中找到一个名字,在那里我正面临这个问题。
首先,我执行了一个运行命令: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)
在这里编码page.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;
}
});
}
请帮助...
答案 0 :(得分:-1)
根据您的代码,我将登录到控制台联系人对象,以查看其具有多少个元素以及这些元素中displayName的值是什么。