如何将我的指令中的变量itemSelect传递给我的控制器?
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'/>