我试图在ng-重复中使用自定义筛选器,但面临以下错误。
错误:$injector:unpr未知提供者未知提供者:$scopeProvider <- $scope <- ngRepeatFinishFilter
这是我的HTML
<tr ng-repeat="person in (sc.people|ngRepeatFinish)| filter:f">
这是我的控制器
(function () {
"use strict";
var app = angular.module('MYAPP');
app.controller("SearchController", ["mainSearch", "$routeParams", "$scope", SearchController]);
app.filter('ngRepeatFinish', function ($timeout, $scope) {
return function (data) {
//var me = this;
var flagProperty = '__finishedRendering__';
if (!data[flagProperty]) {
Object.defineProperty(
data,
flagProperty,
{ enumerable: false, configurable: true, writable: false, value: {} });
$timeout(function () {
delete data[flagProperty];
$scope.setNRCGroupColor();
//me.$emit('ngRepeatFinished');
}, 0, false);
}
return data;
};
});
function SearchController(mainSearch, $routeParams, $scope) {
//
}
}());
发布于 2019-09-29 21:48:48
在过滤器中注入$scope
会给您带来错误,请尝试使用范围如下:
app.filter('ngRepeatFinish', function ($timeout) {
return function (data, scope) {
// scope here will give you all access to $scope
// your other code
};
});
https://stackoverflow.com/questions/58161229
复制