Tôi đang cố gắng để thực hiện một bộ lọc tùy chỉnh, nhưng tôi nhận được lỗi sau:cung cấp Unknown cho bộ lọc tùy chỉnh Ionic/AngularJS
Error: [$injector:unpr] Unknown provider: removeCharsFilterProvider <- removeCharsFilter
Cấu trúc của dự án của tôi là như sau ...
app.js:
var app = angular.module('myApp', ['ionic'])
myController.js:
app.controller('myController', ['$scope', 'removeChars',
function($scope, removeChars) {
//...
}
]);
removeCharsFilter.js:
app.filter('removeChars', function() {
return function(input) {
return input.replace(/-/g, '').replace(/>/g, '');
};
});
myView.html:
<div ng-controller="myController">
<p>{{person.name | removeChars}}</p>
</div>
index.html
<!-- your app's js -->
<script src="js/app.js"></script>
<!-- filters -->
<script src="js/filters/removeCharsFilter.js"></script>
<!-- controllers -->
<script src="js/controllers/myController.js"></script>
Tôi không có ý tưởng tại sao điều này xảy ra, Theo như tôi biết điều này là phải làm việc. Bạn có thể thấy bất cứ điều gì tôi đang thiếu?
bạn đã thử thêm bộ lọc của mình vào dưới dạng phụ thuộc trong tệp app.js chưa? như thế này: var app = angular.module ('myApp', ['ionic', 'removeChars']) –
@Daedalus phát hiện rất tốt! Tuy nhiên sau khi sửa chữa mà tôi vẫn nhận được cùng một lỗi ... – Tiwaz89
@FurkanBasaran Điều đó đã không làm việc ... – Tiwaz89