2016-05-24 12 views
-1
var app = angular.module('myApp', []); 
app.controller('myCtrl', function($scope) { 
    $scope.mylist = ["rag", "VJ", "DK", "Lol", "Mangal"]; 
}); 


app.directive("myDirective", function($compile){ 
    return { 
     template : "<div>SWESH</div>", 
     restrict: 'EA', 
     link: function (scope, element, attrs) { 
      var newel = $compile('<select id="customerDD" ng-options="item for item in mylist"></select>')(scope); 
      element.append(newel); 
     } 

    } 
}); 

に追加されていない、それはチェックアウトフィドルをAngularJS - 動的な要素は、角カスタムディレクティブの動的な要素を追加しようとすると、リンク機能

答えて

0

利用ng-repeat代わりのng-options

var template='<select> <option ng-repeat="item in myList">{{item}}</option></select>' 
var linkFn = $compile(template); 
var content = linkFn(scope); 
element.append(content); 

が動作していない

https://jsfiddle.net/getebin/rpjacmy2/