I am trying to write my first custom filter for AngularJS. I want the ability to recognize that something is either a string or a number, if it is a number, then it has the built-in filter I currently: HTML I thought this would be a better solution for assigning it because it has its own filter, though. This is what I have done so far (yes, I know that these are bare bones ... this is my first one). When it confirms that there is a number, can I apply the angular I In this way you will be able to use your Working here | Formats with the number .
& lt; Table & gt; & Lt; Tr ng-repeat = "data (key, val)" & gt; & Lt; TD & gt; {{}} Key & lt; / TD & gt; & Lt; Td ng-if = "isNumber (val)" & gt; {{Val | Number}} & lt; / TD & gt; & Lt; Td ng-if = "IsNumber (val)" & gt; {{Val}} & lt; / Td> & Lt; / TR & gt; & Lt; / Table & gt; Controller:
$ scope.data = {one: 5568 9, two: "Consider all options", three: 800243, four: "All over", five: "or just beginning"}; $ Scope.isNumber = function (value) {return angular.isNumber (value); };
.filter ('textorumber', function () {return function (input) {If (input of typeof === 'number') {console.log ("I am a number" ); // formatted number as return form} else {console.log ("not a number"); // nothing; just return;} return input;}}}
number to the filter? Or do I have to manually filter it with javascript?
$ filter Service and then filter programmed numbers like this:
angular.module ('filter', []). Filter ('textonumber', ['$ filter Return function ($ filter) return function (input, fractional) {if (hnnA (input)) {return input;} and {return $ filter ('number') (input, fractionSize);}}}}}} ]);
textOrNumber filter in this way:
{{myText | TextOrNumber: 4}}
No comments:
Post a Comment