我有一個角度控制器,其中有一堆函數共享它們之間的數據。問題是,我從函數1返回的數據在函數2中使用,然後在函數2中返回的數據在函數3中使用。我的問題是函數2和函數3首先執行並說沒有找到數據有沒有辦法讓我可以安排功能1先執行。如何在頁面加載後立即執行角JS功能
以下是我的代碼以供參考:
$scope.Read = function() {
var get = ServiceName.Read();
getConfig.then(function (d) {
$scope.RID = d.data;
alert($scope.RID);
}, function (error) {
$log.error('Oops! Something went wrong while fetching the application key data.' + error)
})
}
$scope.Read();
功能2,我想使用的數據:
$scope.getApp = function() {
var sub ={
"RID": $scope.RID
}
var App = ServiceName.getApp(sub);
App.then(function (d) {
$scope.LID = d.data.BUser;
}, function (error) {
$log.error('Opps! Something went wrong in getting appplication defaults');
});
}
$scope.getApp();
任何幫助,將不勝感激!
謝謝!
最好的問候,
桑迪普
是的,我沒有,但要做到這一點,我需要一個值傳遞給函數2總是說範圍是未定義的。我不確定我究竟在哪裏出錯 – Marshall