将 ngModel 指令添加到 Javascript 中的动态元素



有没有办法使用 javascript 将 ng-model 指令应用于创建的元素?在下面的代码中,我希望使用 ng-model 将新的 select 元素绑定到控制器内的作用域变量:

angular.module('myApp').directive('dynamicHtml', function ($q, $http, $compile) {
return {
restrict: 'EAC',
scope: '=',
compile: function(element, attr) {
return function(scope, element, attr) {
var select = document.createElement('select');
// Here I want to use javascript to apply ng-model='controllerVar' 
// to the new select element
element.append(select);
}
}
};
});

哎呀 - 我很抱歉...我忘了编译这个东西...继续。

最新更新