2016-06-14 93 views
0

我使用自定義指令下拉並使用link()方法綁定下拉菜單,但ng-change事件未觸發。Angular JS - ng-change event is not firing

app.directive("reportfId", function(){ 
return { 
    restrict:'AE', 
    template: '<select id="item" multiple="multiple" ng-model="item" class="form-control" style="display:inline-block; " ng-change="binddl()" ></select>', 
    link: function(scope, element, attrs, ctrl) 
    { 
     $.each(scope.freports, function (i, value) { 
      element.append(new Option(value.name, value.id, false, false)); 
     }); 
     element.multiselect({ multiple: false, minWidth: 158, selectedList: 1, height: 100, noneSelectedText: "Select Report ", header: "Select Report" }).multiselectfilter(); 

    } 
     } 
}); 
+0

定義binddl函數在哪裏? – Silvinus

回答

0

如果ng-change="binddl()", binddl()綁定DL()方法之外指令定義,然後爲你創造指令在另一範圍將無法正常工作。

link: function(**scope**, element, attrs, ctrl) 

因此,由於這種ng-isolate-scope將在指令模板代碼活躍..因此,任何外部功能,模型變量不會在指令模板代碼工作..

檢查AngularJS: Call external functions from directive?

+0

但是當我使用ng-option綁定dropwdown時,ng-change事件被觸發。 –