我正在使用离子框架1.3并尝试使用以下方式阅读手机联系人:
cordova plugin add cordova-plugin-contacts
和
.controller('TestControlsCtrl', function($scope, $stateParams, $cordovaContacts) {
$scope.selectContacts = function() {
$cordovaContacts.find().then(function(allContacts) {
$scope.contacts = allContacts;
});
};
});
但我收到此错误
09-26 19:07:25.539 E / Web Console(4188):错误:[$ injector:unpr]未知提供者:$ cordovaContactsProvider< - $ cordovaContacts< - TestControlsCtrl
09-26 19:07:25.539 E / Web Console(4188):http://errors.angularjs.org/1.5.3/ $ injector / unpr?p0 =%24cordovaContactsProvider%20%3C-%20%24cordovaContacts%20%3C-%20TestControlsCtrl < / p>
09-26 19:07:25.539 E / Web Console(4188):at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:13438:12
09-26 19:07:25.539 E / Web Console(4188):at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17788:19
09-26 19:07:25.539 E / Web Console(4188):at Object.getService [as get](file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17941 :39)
09-26 19:07:25.539 E / Web Console(4188):at file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17793:45
09-26 19:07:25.539 E / Web Console(4188):at getService(file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17941:39)
09-26 19:07:25.539 E / Web Console(4188):at injectionArgs(file:///android_asset/www/lib/ionic/js/ionic.bundle.js:17965:58)
09-26 19:07:25.539 E / Web Console(4188):at Object.instantiate(file:///android_asset/www/lib/ionic/js/ionic.bundle.js:18007:18)< / p>
09-26 19:07:25.539 E / Web Console(4188):at $ controller(file:///android_asset/www/lib/ionic/js/ionic.bundle.js:23412:28)
09-26 19:07:25.539 E / Web Console(4188):at [object Object] .appendViewElement(file:///android_asset/www/lib/ionic/js/ionic.bundle.js:59900: 24)
09-26 19:07:25.539 E / Web Console(4188):at Object.render(file:///android_asset/www/lib/ionic/js/ionic.bundle.js:57893:41)at at文件:///android_asset/www/lib/ionic/js/ionic.bundle.js:26794
我做错了什么?请帮忙
答案 0 :(得分:1)
我添加了此插件Cordova插件添加cordova-plugin-contacts
控制器:
$scope.allContacts= [];
function findContacts() {
var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
fields = ["displayName"];
navigator.contacts.find(fields, contactfindSuccess, contactfindError, options);
function contactfindSuccess(contacts) {
for (var i = 0; i < contacts.length; i++) {
alert("Display Name = " + contacts[i].displayName);
$scope.allContacts.push(contacts[i]);
}
}
function contactfindError(message) {
alert('Failed because: ' + message);
}
}