Angularjs Cordova联系人插件不工作
调用此函数后,出现以下错误: “TypeError:无法读取未定义的属性'pickContact'” 使用插件获取联系人并将依赖项注入控制器 此插件仅在设备上可用,不在浏览器中。请在设备上进行测试 对于这个你首先需要安装的插件,这将支持你更多的插件和实现 使用以下命令安装插件Angularjs Cordova联系人插件不工作,angularjs,cordova,hybrid-mobile-app,Angularjs,Cordova,Hybrid Mobile App,调用此函数后,出现以下错误: “TypeError:无法读取未定义的属性'pickContact'” 使用插件获取联系人并将依赖项注入控制器 此插件仅在设备上可用,不在浏览器中。请在设备上进行测试 对于这个你首先需要安装的插件,这将支持你更多的插件和实现 使用以下命令安装插件 cordova plugin add cordova-plugin-contacts 例如: .controller('MyCtrl', function($scope, $cordovaContacts
cordova plugin add cordova-plugin-contacts
例如:
.controller('MyCtrl', function($scope, $cordovaContacts, $ionicPlatform) {
$scope.addContact = function() {
$cordovaContacts.save($scope.contactForm).then(function(result) {
// Contact saved
}, function(err) {
// Contact error
});
};
$scope.getAllContacts = function() {
$cordovaContacts.find().then(function(allContacts) { //omitting parameter to .find() causes all contacts to be returned
$scope.contacts = allContacts;
}
};
$scope.findContactsBySearchTerm = function (searchTerm) {
var opts = { //search options
filter : searchTerm, // 'Bob'
multiple: true, // Yes, return any contact that matches criteria
fields: [ 'displayName', 'name' ] // These are the fields to search for 'bob'.
desiredFields: [id]; //return fields.
};
if ($ionicPlatform.isAndroid()) {
opts.hasPhoneNumber = true; //hasPhoneNumber only works for android.
};
$cordovaContacts.find(opts).then(function (contactsFound) {
$scope.contacts = contactsFound;
};
}
$scope.pickContactUsingNativeUI = function () {
$cordovaContacts.pickContact().then(function (contactPicked) {
$scope.contact = contactPicked;
}
}
});
希望这对你有帮助 需要更多的信息/代码才能在这里提供真正的帮助。快速阅读错误使我认为
navigator
可以,但navigator.contacts
不行。可能是插件安装不正确-您是如何安装的?
.controller('MyCtrl', function($scope, $cordovaContacts, $ionicPlatform) {
$scope.addContact = function() {
$cordovaContacts.save($scope.contactForm).then(function(result) {
// Contact saved
}, function(err) {
// Contact error
});
};
$scope.getAllContacts = function() {
$cordovaContacts.find().then(function(allContacts) { //omitting parameter to .find() causes all contacts to be returned
$scope.contacts = allContacts;
}
};
$scope.findContactsBySearchTerm = function (searchTerm) {
var opts = { //search options
filter : searchTerm, // 'Bob'
multiple: true, // Yes, return any contact that matches criteria
fields: [ 'displayName', 'name' ] // These are the fields to search for 'bob'.
desiredFields: [id]; //return fields.
};
if ($ionicPlatform.isAndroid()) {
opts.hasPhoneNumber = true; //hasPhoneNumber only works for android.
};
$cordovaContacts.find(opts).then(function (contactsFound) {
$scope.contacts = contactsFound;
};
}
$scope.pickContactUsingNativeUI = function () {
$cordovaContacts.pickContact().then(function (contactPicked) {
$scope.contact = contactPicked;
}
}
});