2014-01-20 40 views
0

如何将我的指令中的变量itemSelect传递给我的控制器?AngularJs:从指令到控制器的变量

mDirective.directive('directive', function() { 
    return { 
     restrict: 'A', 
     scope: { 
      options: "=" 
     }, 
     templateUrl: '', 

     link: function(scope, element, attrs) { 
       .........    
      $(element).find('.typeY').on('change', function() { 
       var itemSelect = $(element).find('.typeY').val(); 
      }); 
     } , 

    }; 
}); 
+0

你可以解释不止于此。 –

回答

1

喜欢的东西

mDirective.directive('directive', function() { 
    return { 
     restrict: 'A', 
     scope: { 
      options: "=", 
      selected:"=", 
     }, 
     templateUrl: '', 

     link: function(scope, element, attrs) { 
       .........    
      $(element).find('.typeY').on('change', function() { 
       scope.$apply(function() { 
        scope.selected=value; // value from the element 
       }); 
      }); 
     } , 

    }; 
}); 

在HTML水平

<div directive options='expression' selected='expressionToTheScopeProperty'/>

相关问题