angular-rh-formatting provides simple string formatting in AngularJS. It takes a template string and formats it with the given parameters.
- Get angular-rh-format in one of the following ways:
- Using bower:
$ bower install angular-rh-format
- Download the sources or minified sources
- Include it in the HTML:
<html>
...
<body>
...
<script src="angular-rh-format/dist/angular-rh-format.js"></script>
</body>
</html>
- Add it as a dependency to your AngularJS app:
angular.module('example', [
'rh.format'
]);
As a service:
controller('ExampleCtrl', function($scope, format) {
$scope.text = format('{person} like {0}', 'beer', {person: 'I'});
});
As a filter:
{{'{person} like {0}'|format:'beer':{person:'I'}}}