我有一个使用该$compile
服务生成模板的指令。即使我清楚地在我的范围内设置了数组,它也不会使用ng-options
or生成选择选项。为什么这不起作用?这只是给了我一个没有选项的空白字段。ng-repeat
users
<select>
angular.module("myApp").directive("selectForm", [
'$compile',
function($compile) {
return {
restrict: 'C',
scope: true,
link: function(scope, element, attrs) {
scope.users = [
{ id: 1, name: "User 1" },
{ id: 2, name: "User 2" }
];
element.on('click', function(e) {
var selectHtml = $compile('\
<select\
class="col-lg-2 form-control"\
ng-options="user.id as user.name for user in users">\
</select>\
')(scope);
$(element).html(selectHtml);
});
}
}
}
]);