javascript - Add selectbox from Directives controller -



javascript - Add selectbox from Directives controller -

i trying dynamicaly add together select box directive. same ng alternative works without directive directive gives empty list . please check below fiddle.

i dont want set selectbox in directive template ... need add together them controller only..

fiddle:: http://jsfiddle.net/nfpch/2009/

code:

<select ng-model="selectedoption" ng-options="option alternative in [1,2,3,45,6,8,9,7]"></select>

the right way solve problem utilize directive compile function (read 'compilation process, , directive matching' , 'compile function') modify elements before compilation.

working demo

app.directive('hello', function () { homecoming { restrict: 'e', scope: {}, template: 'hello world', controller: function ($scope, $element, $attrs, $compile) { var el = angular.element('<select ng-model="selectedoption" ng-options="option alternative in [1,2,3,45,6,8,9,7]"></select>'); $compile(el)($scope); $element.append(el); }, } });

javascript angularjs ng-options

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -