5

I am very new to Angularjs. I want to set a value for title attribute, based on a boolean variable.

Sample code attached here.

 <tr ng-repeat="doc in $data" ng-class="{{doc.is_today}} ? 'highlight' : ''" 
                                        ng-attr-title="({{doc.is_today}}) ? 'Today' : ''"> 
     <td>1</td>
     <td>2</td>
     <td>3</td>
     <td>4</td>
     <td>5</td>
</tr>

Thanks,

Deepak raj
  • 269
  • 1
  • 5
  • 19

1 Answers1

4

Remove {{}} in condition

<tr ng-repeat="doc in $data" ng-class="doc.is_today ? 'highlight' : ''" 
                                        ng-attr-title="doc.is_today ? 'Today' : ''"> 
     <td>1</td>
     <td>2</td>
     <td>3</td>
     <td>4</td>
     <td>5</td>
</tr>

Only use {{}} if you want to print the value.

Alternatively you can do the following also

<tr ng-repeat="doc in $data" ng-class="{{doc.is_today ? 'highlight' : ''}}" 
                                            ng-attr-title="{{doc.is_today ? 'Today' : ''}}"> 
         <td>1</td>
         <td>2</td>
         <td>3</td>
         <td>4</td>
         <td>5</td>
    </tr>

Link to fiddle

Aakash
  • 1,751
  • 1
  • 14
  • 21