bind multiple values using ng-bind

26.2k views Asked by At

Can I bind multiple values using ng-bind like so :

<p ng-bind="instructor.first_name instructor.last_name"></p>

Whenever I try this I get the following error:

Error: $parse:syntax Syntax Error

I know I can do the same using the curly braces

<p>{{instructor.first_name}}{{instructor.last_name}}</p>

but I would like to avoid this if I can since the rest of the code base uses ng-bind and I would to stay consistent. Thanks.

3

There are 3 answers

0
Maksym Kosak On BEST ANSWER

You can use "+" for concatenation of the expressions. The following should work for you: <p ng-bind="(instructor.first_name) + (instructor.last_name)"></p>. You can even add filters there <p ng-bind="(instructor.first_name | filterName) + (instructor.last_name)"></p>.

0
djmarquette On

You can always use ng-bind-template to bind and format multiple expressions. This is somewhat of a combination of your ng-bind and curly braces, but I think it's what you are looking for.

Your example would be:

<p ng-bind-template="{{instructor.first_name}} {{instructor.last_name}}"></p>

And of course there is also a ng-bind-html if you are looking to bind an html string.

0
Juan Garassino On

Following the same idea of past answers you can also use ng-bind-html if you want to concat any other chars, that was my case:

  <td ng-bind-html="( com.ref.number | highlight: searchTerm) + '-' + (com.ref.order)">
  </td>