Anthony Pillos Anthony Pillos - 1 year ago 102
AngularJS Question

How to create select option using directives on button click in Angularjs

I want to know how can i duplicate a select tag when i already render it using this lists..

var lists = [{name: "blue"},{name: "green"},{name: "red"},{name: "yellow"}]

and there is a add button to duplicate this select tags.

I created fiddle for this:

I am thinking to used directives for this but i dont know where to start. Thanks guys.

Answer Source

I think you are looking for something like this (Updated):


  <div ng-controller="ListsCtrl">
        {{ mySizes }}
        <select ng-model="selectTag.value"  ng-repeat="selectTag in selectTags">
            <option value="">- - Make Selection - -</option>
            <option ng-repeat="size in sizes" value="{{ }}">{{}}</option>
      <button type="button" ng-click="duplicateSelectTag()">Duplicate Select Tags</button>
      Selected values:
      <ul ng-repeat="selectTag in selectTags">


var app = angular.module("app",[]);
   $scope.sizes = [{name: "blue"},{name: "green"},{name: "red"},{name: "yellow"}]; 
    $scope.duplicateSelectTag = function() {



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download