在頁面加載時,我從數據庫中獲取數據並將其置於$scope.x
中。在我的網絡選項卡中,我從我的數據庫中獲取列表,但它沒有加載到我將很快需要在下拉列表中使用ng-repeat
的變量。但是,頁面加載後,當我單擊一個按鈕來檢索數據並將其放入$scope.x
中時,我已經獲得了這些值。如果我這樣做,我沒有得到頁面加載的值,只需點擊檢索數據到變量的按鈕,我什麼都沒有。我究竟做錯了什麼。下面是我的代碼:來自數據庫的數據未使用角度加載到頁面加載時的變量
$scope.addProject = function() {
debugger;
console.log($scope.clientList);
console.log($scope.userList);
};
$scope.getClients = function() {
debugger;
$http.get('/Clients/GetClients')
.then(function (response) {
$scope.clientList = response.data;
});
};
$scope.getAllUsers = function() {
debugger;
$http.get('/User/GetAllUsers')
.then(function (response) {
$scope.userList = response.data;
})
};
$scope.getClients();
$scope.getAllUsers();
$scope.addProject();
angular.js:14642 ReferenceError:$ q沒有被定義是我得到的.. –
'$ q'服務需要注入到控制器中,就像注入'$ http'服務一樣。 – georgeawg
哇!這工作!你能解釋爲什麼它在我的原始代碼上不起作用嗎?爲什麼我們需要添加$ q.all或承諾? –