Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add more text after using a filter in ng-bind in angularjs

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 
like image 252
laggingreflex Avatar asked Jun 28 '14 04:06

laggingreflex


People also ask

What is the true way to apply multiple filters in AngularJS?

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.

What is the correct way to apply filter in AngularJS?

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.

How does filter work in AngularJS?

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.

How do I filter in NG repeat?

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.


1 Answers

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

like image 114
ryeballar Avatar answered Oct 05 '22 03:10

ryeballar