我有我的控制器和服務這樣的(都在單獨的文件)中:AngularJS如何事件偵聽器後更新視圖/範圍
.controller('authCtrl',['$scope','MyConnect',function($scope,MyConnect){
/***************Testing Area******************/
console.log("connecting");
MyConnect.initialize();
$scope.myID = ??? //I want this to be updated
}
.factory('MyConnect', ['$q', function($q) {
var miconnect = {
initialize: function() {
this.bindEvents();
},
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function() {
thirdPartyLib.initialize();
miconnect.applyConfig();
},
applyConfig: function() {
if (thirdPartyLib.isReady()) {
//I want in here to update $scope.myID in controller and reflect the changes in UI textbox
//$scope.myID = thirdPartyLib.id(); //something like this will be good
}
else {
}
}
}
return miconnect;
}])
所以,我不知道如何更新$ scope.myID (這是一個文本框)。我不確定如何在事件監聽器之後執行回調。通常,如果我可以使用ajax,然後等待數據到達。
主要的是,我需要使用第三方庫(專有),並且基於指南,在設備準備好之後調用thirdPartyLib.initialize(),然後在實際調用之前檢查thirdPartyLib.isReady函數來檢索id。