4
這裏我的問題:
我試圖建立一個角指令,這將使用ng-table
內。 問題在於輸入參數tableData
初始化爲空數組,因爲它是在用戶單擊按鈕時從指令的外部設置的。
因此,我在tableData
上添加了一塊手錶,並在tableData
更改時嘗試重新加載表。
但是,differ.resolve函數最終會出現以下異常。
請幫
指令使用
<table-multiselect table-data="objectArray"></table-multiselect>
這是我臨時
TableMultiselect.tmpl.cshtml
<table ng-table="multiselect" class="table">
<tr ng-repeat="feature in $data">
<td data-title="'Id'" sortable="'id'">{{feature .id}}</td>
<td data-title="'Name'" sortable="'name'">{{feature .name}}</td>
<td data-title="'Type'" sortable="'type'">{{feature .type}}</td>
</tr>
</table>
控制器
.directive('TableMultiselect', function (ngTableParams) {
return {
restrict: 'E',
templateUrl: 'TableMultiselect.tmpl.cshtml',
scope: {
tableData: '='
},
controller: function ($scope) {
var buildMultiSelectTable = function() {
return new ngTableParams({
page: 1,
count: 10,
sorting: {
id: 'asc'
},
filter: {},
}, {
counts: [10],
total: $scope.tableData.length, // length of data
getData: function ($defer, params) {
var data = $scope.tableData;
if (data.length <= 10) {
params.settings({ 'counts': [] });
}
params.total(data.length);
$defer.resolve(data);
}
});
};
$scope.multiselect = buildMultiSelectTable();
$scope.$watch('tableData', function (newValue, oldValue) {
if ($scope.tableData != undefined && $scope.tableData.length > 0) {
$scope.multiselect.reload();
}
});
},
};
});
錯誤
是從您粘貼代碼明顯TypeError: Cannot set property '$data' of null
at angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:3095
at l.promise.then.J (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:101)
at angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:102
at h.a.$get.h.$eval (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:113)
at h.a.$get.h.$digest (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:110)
at h.a.$get.h.$apply (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:113)
at m (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:72)
at w (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:77)
at XMLHttpRequest.B.onreadystatechange (angular?v=M5FbIdPbFPNnbg6slbXZa4DR7EKc6tL5nLLGAVGYAa41:79)