以下是我的app.js代码。
var app = angular.module('SampleApp', ['ngSanitize'])
.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'
}
}
}
});
我编写了一个名为'Ordinal。
的自定义过滤器<input type="text" ng-model="uuuu" />
<span ng-bind="uuuu | ordinal"></span>
当我尝试按上述方法使用时,我的误差低于此值。
错误:
[$ injector:unpr]未知提供者:ordinalFilterProvider&lt; - ordinalfilter