[英]How to view the data from server using $http.get
我有一個名為$scope.mobileBrandArray= [];
的空數組$scope.mobileBrandArray= [];
現在,我正在嘗試使用函數內的$http.get()
從服務器獲取數據。
這是我的app.js
代碼
app.controller('myCtrl' , function($scope , $http){
$scope.mobileBrandArray = [];
$scope.getMobileBrandArray = function(){
$http.get("http://192.168.101.4:9090/Mobile_ERP/rest/brand/")
.success(function(response) {
console.log(response);
console.log(response[0].brandKey);
$scope.mobileBrandArray=response;
console.log($scope.mobileBrandArray);
})
.error(function(response) {
console.log(response);
alert("error ");
})
};
});
在這里,我無法在UI中查看數據,但是我嘗試$http.get()
不帶$scope.getMobileBrandArray();
$http.get()
函數$scope.getMobileBrandArray();
它工作正常,但我需要在$scope.getMobileBrandArray();
之外的數組$scope.getMobileBrandArray();
這是我的HTML
代碼
<tr ng-repeat="mobileBrand in mobileBrandArray" ng-include="getTemplate(mobileBrand)">
<script type="text/ng-template" id="display">
<td>{{mobileBrand.brandCode}}</td>
<td>{{mobileBrand.brandName}}</td>
<td>{{mobileBrand.brandStatus}}</td>
<td>{{mobileBrand.brandCreatedOn}}</td>
<td>
<button type="button" class="btn btn-primary" ng-click="editMobileData(mobileBrand)">Edit</button>
<button type="button" class="btn btn-danger" ng-click="deleteMobileData(mobileBrand)">Delete</button>
</td>
</script>
<script type="text/ng-template" id="edit">
<td><input type="text" ng-model=mobileBrand.brandCode class="form-control input-sm"/></td>
<td><input type="text" ng-model=mobileBrand.brandName class="form-control input-sm"/></td>
<td><input type="text" ng-model=mobileBrand.brandStatus class="form-control input-sm"/></td>
<td><input type="text" ng-model=mobileBrand.brandCreatedOn class="form-control input-sm"/></td>
<td>
<button type="button" class="btn btn-primary" ng-click="updateMobileData(mobileBrand)">Save</button>
<button type="button" class="btn btn-danger" ng-click="reset()">Cancel</button>
</td>
</script>
</tr>
我看不到您在哪里調用getMobileBrandArray()
函數。 您有兩種選擇:
將ng-init='getMobileBrandArray()'
到表頂部以自動運行$http.get
函數。
或將ng-click='getMobileBrandArray()'
到要啟動get函數的按鈕上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.