这是我的问题:
我正在尝试以角度构建一个指令,该指令将使用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)