简体   繁体   中英

AngularJS “{{}}” insite title attribute isn't working

I using this HTML & AngularJS code:

<td class="domain-col" ng-init="msg='error message'">
    <span class="label label-warning" ng-show="page.ErrorCode == 11" data-toggle="tooltip" title="{{ msg }}">Error</span>
</td>

This code is working inside ng-repeat in order to generate rows in table. Each row in the table is represented with page object. Each page has ErrorCode .

On ng-init I converting the error code to user friendly UI message, which will be printed to title attribute.

The problem is that instead print the error message into title attribute, the value of this attribute became "{{ msg }}". The value of title attribute after running the code:

  • Actual : "{{ msg }}" string.
  • Expected : "error message".

Why this happens? How to fix this?

You could use ng-attr-*="{{expression}}" directive here, in which * means attributeName , So basically what it does is. evaluated expression from interpolate and add evaluated value in that attribute.

ng-attr-title="{{msg}}"

您可以使用 :

ng-attr-title="{{msg}}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM