javascript - check value of isolated scope variable in link function - directives in angular -


i have following html:

<div class="jumbotron" ng-controller="protocolctrl pctrl">      <!--in modal can add/change/delete data-->      <modal-directive list="pctrl" headers="['id', 'protocol']"></modal-directive>  </div> 

in modal-directive.html, in body, this:

<!-- modal body-->  <div class="modal-body">      <table-directive list=list headers=headers></table-directive>  </div> 

i want check on list parameter pass in. if it's equal value, want append html body

my directive looks this

.directive('modaldirective', function(){     return {         restrict: 'e',         templateurl: '/directives/modal-directive.html',         scope: {             list: '=',             headers: '='         },         link: function(scope, element, attrs){             if(scope.list == 'pctrl'){                 element.find('.modal-body').append('this test.')             }         }     }; }); 

but doesn't append anything. if drop if check appends fine.

i'm new angular, if can tell me how can achieve this, i'd appreciated it.

edit

this how loop through data in table-directive.html

 <tr ng-repeat="l in list.list">       <!--access actual values inside each of objects in array-->       <td ng-repeat="data in l"> {{ data }} </td>       <td>          <button type="button" class="btn btn-primary btn-sm"                  data-toggle="modal">edit</button>      </td>       <td>         <button type="button" class="btn btn-danger btn-sm" ng-click="list.removedata(l)"                     data-dismiss="modal">remove</button>      </td>   </tr> 

if put

<modal-directive list="pctrl" headers="['id', 'protocol']"></modal-directive> 

and

....   scope: {         list: '=',         headers: '='     }, ..... 

list: '=' check list attr of element , execute argument expression not string think trying 'pctrl' string not scope variable value change list="'pctrl'" pass string

<modal-directive list="'pctrl'" headers="['id', 'protocol']"></modal-directive> 

or

get attr string use @

....   scope: {         list: '@',         headers: '='     }, ..... 

here explanation.

here angular official doc

update

if need check string value of attr, can use attrs.list

so use inside directive as

if(attrs.list === 'pctrl'){     element.find('.modal-body').append('this test.') } 

Comments