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

南笙酒味 提交于 2019-12-20 09:33:38

问题


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

回答1:


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




回答2:


You can do something like this:

<h1 ng-bind="'{{input | filter}}' + ' more stuff'"></h1>

Here's an example: http://plnkr.co/edit/rEva7FTPFtr3im7RUlQk?p=preview



来源:https://stackoverflow.com/questions/24463473/add-more-text-after-using-a-filter-in-ng-bind-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!