简体   繁体   中英

Directive scope variable

I am using a directive for three consecutive time in html page, the scope variable i am passing to different at every time but it is taking all the scope variable from the third directive ?, for example first time,

<my-dir is-active=true></my-dir> 

sec time,

<my-dir is-active="true"></my-dir>

third time,

<my-dir is-Active="true" is-action="true"><my-dir>

JS:

angular
.module('app')
.directive("myDir", function(){
 scope:{
  isActive:'@',
  isAction:'@'
 },
controller:[function('$scope'){
  $scope.isAction ? doAction() : doActive();

 function doAction()
 {
    console.log('in action');
  }

  function doActive()
  {
    console.log('in active');
  }
}]
})

here at every time I am getting "In action" log three time ? it should be only one time as I am not passing the "IsAction" scope from the directive for the first two time ?

I am pretty sure your issues were just syntax errors. If you correct those it seems to work correctly.

Plunker

.directive("myDir", function(){
  return {
   scope:{
    isActive:'@',
    isAction:'@'
   },
   controller:function($scope){
      $scope.isAction ? doAction() : doActive();

      function doAction()
      {
        console.log('in action');
      }

      function doActive()
      {
        console.log('in active');
      }
    }
  }
})

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