我的应用程序在ng-init上执行get请求,如下所示:
<div class="container-fluid" ng-controller = "dashboardCtrl" ng-init = "getTables('<?php echo base_url();?>')">
<div class="row">
<div id="side-bar" class="col-md-2 col-lg-2">
<div ng-repeat = "table in tables" class="table-name" ng-click = "getColumns(table)">
<p>{{table}}</p>
</div>
</div>
然后我想通过使用ng-click指令执行另一个get请求,该指令由上面看到的ng-repeat自动生成。问题是我正确地获取服务器端数据但我的范围变量在我的视图中没有得到更新。我已尝试使用$ scope。$ apply(fn)和$ scope。$ apply()但我得到$ digest in progress错误,这是我的控制器:
require(['app'], function(app){
app.controller('dashboardCtrl',function($scope,$http){
$scope.base_url = "";
$scope.tablename = "";
$scope.tables = "";
$scope.columns = [];
$scope.getTables = function(base_url){
$scope.base_url = base_url;
$http.get($scope.base_url + 'index.php/dashboard/getTables').success(function(data){
$scope.tables = data; //this works fine
});
}
$scope.getColumns = function(param){
$scope.tablename = param;
$http({
url: $scope.base_url + 'index.php/dashboard/getColumns',
method: "GET",
params: {tableName: $scope.tablename}
}).success(function(data){
$scope.columns = data; //request works but columns doesnt get updated in view
console.log($scope.columns); //server data is showed in console
});
}
});
});
最后,这是应该呈现并遍历$ scope.columns变量的部分:
<section id="table-data">
<p ng-repeat="column in columns">{{column}}</p> <!-- Doesnt display anything -->
</section>
有任何建议或想法吗?