我有一个名为$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 ");
})
};
});
此处我无法在用户界面中查看我的数据,但我尝试使用$http.get()
函数而$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>
答案 0 :(得分:0)
我不知道你在哪里调用getMobileBrandArray()
函数。你有两个选择:
将ng-init='getMobileBrandArray()'
添加到表格顶部以自动运行$http.get
功能。
或将ng-click='getMobileBrandArray()'
添加到要启动get函数的按钮。