The use of filter in AngularJS combat II

The filter in blog post 1 is the filter that comes with angular, which generally does not satisfy our use. We can customize the filter.
1. Customize the filter to reverse the string
<div>{{ceshi|reverse}}</div>


app.filter('reverse', function() {
  return function(text) {
  return text.split("").reverse().join("");
		};
});

app.controller("crl", function($scope, $filter) {
		$scope.ceshi="abcd";
		
	});

The effect is: dcba
Second, use multiple filters
<div>{{ceshi|reverse|uppercase}}</div>

The effect is: DCBA
3. Use filter in the controller to
inject the filter
<div>{{date}}</div>
	<div>{{reverse}}</div>

app.controller("crl", function($scope, $filter) {
		$scope.reverse = $filter('reverse')("abcd");
		$scope.date = $filter('date')(new Date());
	});

The effect is
Aug 24, 2017
dcba

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564402&siteId=291194637