[英]Simple Angular JS Filter not working
我试图在我的项目中插入一个简单的过滤器,但是它不起作用,没有错误……只是不起作用。 我正在复制并粘贴所有内容
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}}
无论如何,您都不会退货,因为400不匹配“ else if”,并且在这种情况下您不会退货。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.