0
我想插入一個簡單的過濾器到我的項目,但它不工作,沒有錯誤...只是不工作。我複製和簡單的角JS過濾器不工作
https://scotch.io/tutorials/building-custom-angularjs-filters
粘貼一切Filter.js
angular.module('starter.filters', [])
// Setup the filter
.filter('ordinal', function() {
// Create the return function
// set the required parameter name to **number**
return function(number) {
// Ensure that the passed in data is a number
if(isNaN(number) || number < 1) {
// If the data is not a number or is less than one (thus not having a cardinal value) return it unmodified.
return number;
} else {
// If the data we are applying the filter to is a number, perform the actions to check it's ordinal suffix and apply it.
var lastDigit = number % 10;
if(lastDigit === 1) {
return number + 'st'
} else if(lastDigit === 2) {
return number + 'nd'
} else if (lastDigit === 3) {
return number + 'rd'
} else if (lastDigit > 3) {
return number + 'th'
}
}
}
});
依賴
angular.module('starter', ['ionic', 'starter.controllers','starter.filters','ngCordova'])
的index.html
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/filters.js"></script>
HTML:
{{400 || ordinal}}
這是行不通的....爲什麼?
感謝您的幫助
你有什麼錯誤嗎? –
刪除一個'|'。它應該是'{{400 | ordinal}}' – devqon
真棒@devqon ...只需將您的答案放在下面,我會將其標記爲已回答 – MehdiN