angularjs filter Error: $injector:unpr Unknown Provider
angularjs filter Error: $injector:unpr Unknown Provider
我正在尝试在 ng-repeat 中使用自定义过滤器,但遇到如下错误。
Error: $injector:unpr Unknown Provider
Unknown provider: $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) {
//
}
}());
在过滤器中注入 $scope
会给您带来错误,请尝试使用您的范围:
app.filter('ngRepeatFinish', function ($timeout) {
return function (data, scope) {
// scope here will give you all access to $scope
// your other code
};
});
我正在尝试在 ng-repeat 中使用自定义过滤器,但遇到如下错误。
Error: $injector:unpr Unknown Provider Unknown provider: $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) {
//
}
}());
在过滤器中注入 $scope
会给您带来错误,请尝试使用您的范围:
app.filter('ngRepeatFinish', function ($timeout) {
return function (data, scope) {
// scope here will give you all access to $scope
// your other code
};
});