Reputation: 8765
I have a directive that uses the $compile
service to generate a template. It won't generate the select options using ng-options
or ng-repeat
, even though I clearly have the users
array set in my scope. Why doesn't this work? This just gives me a blank <select>
field with no options.
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);
});
}
}
}
]);
Upvotes: 1
Views: 1209