[英]Apache cordova var not displayed in html
我的應用程序在Android上使用angular&apap cordova開發時遇到問題。
首先,我從智能手機獲取聯系人列表,並將其存儲在var中:$ scope.listecontacts
// alert('nb contacts '+contacts.length);
for (var i = 0; i < contacts_1.length; i++)
{
if(contacts_1[i].phoneNumbers != null && contacts_1[i].name != null && typeof contacts_1[i].phoneNumbers != 'undefined')
{
if($scope.numero_tel==0)
{
$scope.numero_tel = contacts_1[i].phoneNumbers[0].value;
}
$scope.listecontacts.push(contacts_1[i]);
}
}
在第二次,我嘗試將其顯示在html dom中,如下所示:
<div ng-repeat="t in listecontacts" >{{(t.name.formatted)}}</div>
當我啟動應用程序時,它運行良好,但是當我返回主頁然后進入獲取聯系人列表的視圖時,DIV不會填充聯系人列表。
我檢查了變量:$ scope.listecontacts,它不是空的...。
有誰遇到過這個問題?
你有什么主意嗎?
非常感謝 !
我試圖通過這種方式使用服務:
app.factory('ContactService', function($window, $q, $rootScope){
var options = new ContactFindOptions();
options.filter = "";
options.multiple = true;
var filter = ["displayName", "name","phoneNumbers"];
// navigator.contacts.find(filter, onSuccess, onError, options);
return {
getContactList : function(onSuccess, onError){
navigator.contacts.find(filter,function(contacts){
$rootScope.$apply(function(){
onSuccess(contacts);
})
}, function(){
$rootScope.$apply(function(){
onError();
})
}, options)
}
}
})
然后在我的控制器中:
$scope.get_contacts = function()
{
/*alert('get_contacts');*/
try
{
ContactService.getContactList(function(contacts)
{
但是沒有什么變化,我通過USB和Chrome在控制台上檢查了變量,數組的文件名是thje,但是HTML不顯示數據。
謝謝你的幫助 !
實際上我的服務運行良好,我只需要更改
這個 :
<option ng-repeat="t in listecontacts" value="{{(t.phoneNumbers[0].value)}}" >{{(t.name.formatted)}}</option>
對此
<option ng-repeat="t in listecontacts.liste_1" value="{{(t.phoneNumbers[0].value)}}" >{{(t.name.formatted)}}</option>
因為我使用對象而不是“ listecontacts”數組
$scope.listecontacts= {
liste_1: []
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.