Balu Balu - 4 months ago 7
AngularJS Question

Issue while adding controls dynamically

I was adding and removing controls dynamically. However, I have a small requirement.

Below one is Jsbin code.
https://jsbin.com/tuxacitoju/1/edit?html,output


  1. Open the link.

  2. Click “Adperson”

  3. Now click Remove two times.



Observe, all control are removed and then you are not allowed to add controls.

My page should have at least one set of controls.

Thanks,
Balu

Answer

You can simply do:

  $("#associationRemove").on("click", function(){
      if($(".cloneMe").length > 1){
        $(".cloneMe:last").remove();  
      }
  });
Comments