Podążam za this tutorial i utworzyłem odpowiednio spersonalizowane filtry niestandardowe. Ten ostatni powoduje jednak zniknięcie pierwszego; podczas korzystania z filtru truncate
jest to wyjątek. Jak utworzyć wiele filtrów w module?Tworzenie wielu niestandardowych filtrów w jednym module w Angularjs
angular.module('filters', []).filter('truncate', function() {
return function (text, length, end) {
if (isNaN(length))
length = 10;
if (end === undefined)
end = "...";
if (text.length <= length || text.length - end.length <= length) {
return text;
}
else {
return String(text).substring(0, length-end.length) + end;
}
};
});
angular.module('filters', []).filter('escape', function() {
return function(text) {
encodeURIComponent(text);
};
});
dzięki, które sprawia, że sens – bicycle
Jak byś zrobił to samo, ale z oddzielnym plikiem dla każdego filtra? –
Przepraszamy za odpowiedź na moje własne pytanie, myślę, że byłoby to: 'angular.module ('filters', [])' 'angular.module (' filtry ") filter (" truncate ", function() {});' 'angular.module ('filters') .filtr (" escape ", function() {});' –