我在控制器中有一個作用域函數,我需要從指令中觸發它,指令是下拉菜單,所以無論何時我要更改值,我需要從指令觸發一個函數控制器。從Angular中的指令調用控制器作用域函數
HTML
<dropdown-single-select filter-params=false eventlstn="selectTab('summary')" api-params="serviceApiParams" select-options="filterData.classFilter" selected-value="filterData.selectedClassOptions" ></dropdown-single-select>
指令
.directive('dropdownSingleSelect',['$document', function($document){
return {
scope: {
onSelect: '&',
selectOptions: '=',
isoFilterParams:'=filterParams',
isoEventListener:'=eventListener',
selectedValue:'=',
defaultOption:'=',
disable:'&',
apiParams:'='
},
restrict: 'E',
templateUrl: 'commonActions/waggle-single-select.tpl.html',
link: function(scope, element, attr) {
scope.toggleOptions= function(){
scope.showOptions = !scope.showOptions;
}
scope.selectOption = function(option){
if(scope.apiParams.reload){
scope.apiParams.classViewId=option.classViewId;
scope.$apply(attr.eventlstn);
}
}
};
}])
控制器
.controller('studentSummaryReportCtrl', ['$scope', function ($scope){
$scope.selectTab=function(data){
console.log(data);
}
}])
下拉工作正常和ALS o selectoption工作正常,但涉及到作用域。$ apply(attr.eventlstn);它不工作
您可以在法傳遞與「&」的指令,只是把它從向鏈路功能類似這樣的'scope.selectTab(「摘要」)' –
感謝您的回答,但我打過電話與功能$發射,它像一個魅力:) –