我在AngularJS中創建了一個自定義指令。 在鏈接函數中,我將ng-model和ng-options屬性添加到內部模板,但不幸的是綁定不起作用。 但是,當我把內部模板放入我的html文件中時,一切正常。與AngularJS綁定的指令
application.directive("customSelect", function() {
var directive = {
restrict: 'E',
template: '<select name="ArrDeplocation" class="arrdepSelect"></select>',
link: function (scope, elem, attr) {
console.log('scope: ', scope);
console.log('element: ', elem);
console.log('attribute: ', attr);
$(elem.children()[0]).attr('ng-model', 'model.selectedCity');
$(elem.children()[0]).attr('ng-options', 'city for city in model.cities');
$(elem.children()[0]).selectmenu();
}
};
return directive;
});
試過了,它拋出異常,說$ apply正在處理 – Dimkin 2013-04-25 07:32:15