AngularJs:从指令到控制器的变量
如何将指令中的变量itemSelect传递给控制器AngularJs:从指令到控制器的变量,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,如何将指令中的变量itemSelect传递给控制器 mDirective.directive('directive', function() { return { restrict: 'A', scope: { options: "=" }, templateUrl: '', link: function(scope, element, attrs) {
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();
});
} ,
};
});
差不多
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级别
你可以解释更多。