title: Angularjs dynamically adding and removing elements using directive
body: <p>I used directive for creating contact form. Initially i create customerForm directive for displaying customer form. In that form i have one button, when we click on add button, called getData function and that function internally used newDirective for displaying ul list. for that i used $compile api for compiling html code. that is fine and its also display list value and remove button when we click on remove button, its called scope.remove() function. But its delete only ones. after that i cant remove any element (i.e. button). i dont know why its happening. please help me. <a href="http://jsfiddle.net/TusharBalar/mcVfK/1332/" rel="nofollow">jsfiddle</a></p>
  
  <h2>index.html</h2>
  
  <pre><code>&lt;div class="container"&gt;
      &lt;customer-form&gt;&lt;/customer-form&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h2>app.js</h2>
  
  <pre><code>angular.module('sanshaApp', [])
  
  .directive('newDirective', function ( $compile ){
          return {
              restrict: 'E',
              template: 
                  '&lt;ul&gt;' +
                      '&lt;li&gt;{{somoe value here}}' +
                          '&lt;button ng-click="remove()"&gt;Remove&lt;/button&gt;' +
                      '&lt;/li&gt;'+
                  '&lt;/ul&gt;',
              link: function (scope, element, attributes) {
                  //called when click on Remove button  
                  scope.remove = function () {
                      element.remove();
                  }
              }
          }
      })
  .directive('customerForm', function($compile) {
  
          return {
  
              scope: {
  
              },
  
              restrict: 'E',
  
              transclude: true,
  
              templateUrl: "../../views/customer-form.html",
  
              controller: "mainCtrl",
  
              link: function(scope, element, attrs, mainCtrl) {
  
                  scope.getData = function() {
                     //create new element new-directive
                     $newDirective = angular.element('&lt;new-directive&gt;');
                     element.append($newDirective);
                     //compile html DOM
                     $compile( $newDirective )(scope);
                  }
              }
          }
     })
  
  .controller("mainCtrl", ['$scope', function($scope) {
  
    }])
  </code></pre>
  
  <h2>customer-form.html</h2>
  
  <pre><code>   &lt;div class="form-group row"&gt;
          &lt;label for="name" class="col-lg-2 form-control-label"&gt;Customer name&lt;/label&gt;
          &lt;div class="col-lg-4"&gt;
              &lt;input type="text" class="form-control" ng-model="name.aa" placeholder="customer name"&gt;
          &lt;/div&gt;
          &lt;label for="email" class="col-lg-2 form-control-label"&gt;Email address&lt;/label&gt;
          &lt;div class="col-lg-4"&gt;
              &lt;input type="email" class="form-control" ng-model="name.email" placeholder="Email"&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-lg-4"&gt;
             &lt;button class="btn btn-default" value="add" ng-click="getData()"&gt;
                 &lt;span class="glyphicon glyphicon-plus"&gt;&lt;/span&gt;
             &lt;/button&gt;
          &lt;/div&gt;
       &lt;/div&gt;
  </code></pre>