So I want to put a variable through a filter inthe ng-bind directive
ng-bind="input | filter"
but I want to insert more text
ng-bind="input | filter + 'more' "
but this isn't working. Is there a way to add more text in ng-bind, like you could if you were simply using {{}}
:
{{input | filter}} more
Using filters in view templates Filters can be applied to the result of another filter. This is called "chaining" and uses the following syntax: {{ expression | filter1 | filter2 | ... }} E.g. the markup {{ 1234 | number:2 }} formats the number 1234 with 2 decimal points using the number filter.
In AngularJS, you can also inject the $filter service within the controller and can use it with the following syntax for filter. Syntax: $filter("filter")(array, expression, compare, propertyKey) function myCtrl($scope, $filter) { $scope. finalResult = $filter("filter")( $scope.
The “filter” Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array.
The ng-repeat values can be filtered according to the ng-model in AngularJS by using the value of the input field as an expression in a filter. We can set the ng-model directive on an input field to filter ng-repeat values.
Instead of interpolating(using {{}}
) something in the ng-bind
directive you can simply enclose the filtered value with a parenthesis and append your text.
<h1 ng-bind="(input | filter) + ' more stuff'"></h1>
furthermore, if the text you want to add is not in any way dynamic then I suggest you append another element to bind the filtered value and then add the text after that element.
e.g.
<h1><span ng-bind="(input | filter)"></span> more stuff</h1>
This saves you one concatenation process.
Example here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With