所以在Angular中,我试图将ng-Table绑定到数据集,但似乎不能用于我的响应数据。我想我的问题就在这里, “” - self.tableParams = new NgTableParams({},{dataset:'data'}); - “” 但我不确定。此外,我没有错误控制台。 有人可以说清楚,谢谢。
控制器:
UtilityApp.controller('u_CompaniesController', function ($scope, $http, NgTableParams) {
$scope.message = "Companies";
$scope.myData = [];
$http({
method: 'GET',
url: '/Utility/GetCompanies',
}).then(function successCallback(response) {
var self = this;
var data = response.data;
self.tableParams = new NgTableParams({}, { dataset: 'data' });
}, function errorCallback(response) {
alert("error");
});
});
伍-表
<div ng-controller="u_CompaniesController">
<table id="tblCompanies" ng-table="vm.tableParams" class="table" show-filter="true">
<tr ng-repeat="c in $tableParams">
<td title="'CompanyCd'" filter="{ CompanyCd: 'text'}" sortable="'CompanyCd'">
{{c.CompanyCd}}
</td>
<td title="'CompanyName'" filter="{ CompanyName: 'text'}" sortable="'CompanyName'">
{{c.CompanyName}}
</td>
</tr>
</table>
</div>
答案 0 :(得分:0)
尝试在控制器声明下将var self = this
移到右侧。您还应该通过ng-controller="u_CompaniesController as vm"
更新您的html。阅读this blogpost有关Controller as Syntax的更多信息。
或者只是使用$scope
,如果您刚开始使用角度,我建议您使用vm
。在这种情况下,请从您的html ng-table="tableParams"
$scope.tableParams = new NgTableParams({}, { dataset: 'data' });
UtilityApp.controller('u_CompaniesController', function ($scope, $http, NgTableParams) {
$scope.message = "Companies";
$scope.myData = [];
$http({
method: 'GET',
url: '/Utility/GetCompanies',
}).then(function successCallback(response) {
var data = response.data;
$scope.tableParams = new NgTableParams({}, { dataset: 'data' });
}, function errorCallback(response) {
alert("error");
});
<强>控制器强>
<div ng-controller="u_CompaniesController">
<table id="tblCompanies" ng-table="tableParams" class="table" show-filter="true">
<tr ng-repeat="c in $tableParams">
<td title="'CompanyCd'" filter="{ CompanyCd: 'text'}" sortable="'CompanyCd'">
{{c.CompanyCd}}
</td>
<td title="'CompanyName'" filter="{ CompanyName: 'text'}" sortable="'CompanyName'">
{{c.CompanyName}}
</td>
</tr>
</table>
</div>
<强> HTML 强>
<select>