Q:

Dynamic buttons work on first try but not second

I have buttons that will add new search section and remove section, however if you click the first section, then you remove the first section and then add first section again the first section doesnt get the removal buttons, how come the button isnt working?
TLDR; Go to fiddle Click Add, Remove, Add. How come no remove button?
FIDDLE
HTML
<div ng-controller="SearchCntrl">
  <form class="form-horizontal" role="form">
    <div ng-repeat="section in searchSection">
      <section ng-model="searchSection" class="panel panel-primary" style="padding:10px 10px 2px 15px;">
        <div class="form-group">
          <label class="col-sm-2 control-label">Search:</label>
          <div class="col-sm-6">
            <select class="form-control" ng-model="chosenColumn" ng-options="col.label for col in filterableColumns" ng-change="SetSearchType(chosenColumn)"></select>
          </div>
        </div>
        <div class="form-group" ng-if="SearchType=='str'">
          <label class="col-sm-2 control-label">Condition:</label>
          <div class="col-sm-6">
            <select class="form-control" ng-model="chosenStringCondition" ng-options="condition.label for condition in stringConditions" ng-change="SetSearchCondition(chosenStringCondition)"></select>
          </div>
        </div>
        <div class="form-group" ng-if="SearchType=='int'">
          <label class="col-sm-2 control-label">Condition:</label>
          <div class="col-sm-6">
            <select class="form-control" ng-model="chosenIntegerCondition" ng-options="condition.label for condition in integerConditions"></select>
          </div>
        </div>
        <div class="form-group" ng-if="SearchType=='sel'">
          <label class="col-sm-2 control-label">Condition:</label>
          <div class="col-sm-6">
            <select class="form-control" ng-model="chosenSelectCondition" ng-options="condition.label for condition in selectConditions"></select>
          </div>
        </div>
        <div class="form-group" ng-if="SearchType=='str' && SearchCondition != 'COMMON_ITEM'">
          <label class="col-sm-2 control-label">Term:</label>
          <div class="col-sm-6">
            <input type="text" class="form-control" ng-model="searchTerm" placeholder="Search Term" />
          </div>
        </div>
        <div class="form-group" ng-if="SearchType=='int'">
          <label class="col-sm-2 control-label">Term:</label>
          <div class="col-sm-6">
            <input type="number" class="form-control" ng-model="searchTerm" placeholder="Search Term" />
          </div>
        </div>
        <div class="form-group" ng-if="SearchType=='sel'">
          <label class="col-sm-2 control-label">Status:</label>
          <div class="col-sm-6">
            <select class="form-control" ng-model="chosenStatus" ng-options="status.label for status in statusColors"></select>
          </div>
        </div>
        <div class="form-group" ng-show="!showAddAdditionalSearchParameters(section)">
        <div class="col-sm-8">
          <div style="text-align:right;">
            <button type="button" ng-click="RemoveSearchSection(section)" class="btn btn-danger"><i class="fa fa-minus"></i> Remove Search Parameters</button>
          </div>
          </div>
        </div>
        <div class="form-group" ng-show="showAddAdditionalSearchParameters(section)">
        <div class="col-sm-8">
          <div style="text-align:right;">
            <button type="button" ng-click="AddNewSearchSection()" class="btn btn-success"><i class="fa fa-plus"></i> Add Additional Search Parameters</button>
          </div>
        </div>
        </div>
      </section>
    </div>
  </form>
</div>

JavaScript:
var app = angular.module('app', []);

app.controller('SearchCntrl', ['$scope', function($scope) {
  $scope.searchSection = [{
    id: 'section0'
  }];
  $scope.filterableColumns = [{
    value: 1,
    label: "Product Code",
    type: "str"
  }, {
    value: 2,
    label: "Product Name",
    type: "str"
  }, {
    value: 3,
    label: "Quantity Avail",
    type: "int"
  }, {
    value: 4,
    label: "Status",
    type: "sel"
  }];
  $scope.chosenColumn = $scope.filterableColumns[1];

  $scope.stringConditions = [{
    value: 'LIKE',
    label: "LIKE"
  }, {
    value: 'CONTAINS',
    label: "CONTAINS"
  }, {
    value: 'EQ',
    label: "EQUALS"
  }, {
    value: 'DNC',
    label: "DOES NOT CONTAIN"
  }, {
    value: 'DNE',
    label: "DOES NOT EQUAL"
  }, {
    value: 'COMMON_ITEM',
    label: "IS COMMON ITEM"
  }];
  $scope.chosenStringCondition = $scope.stringConditions[1];

  $scope.integerConditions = [{
    value: 'EQ',
    label: "EQUALS"
  }, {
    value: 'LT',
    label: "LESS THAN"
  }, {
    value: 'GT',
    label: "GREATER THAN"
  }];
  $scope.chosenIntegerCondition = $scope.integerConditions[1];

  $scope.selectConditions = [{
    value: 'EQ',
    label: "EQUALS"
  }];
  $scope.chosenSelectCondition = $scope.selectConditions[0];

  $scope.statusColors = [{
    value: 'red',
    label: "Red"
  }, {
    value: 'yellow',
    label: "Yellow"
  }, {
    value: 'green',
    label: "Green"
  }];
  $scope.chosenStatus = $scope.statusColors[2];

  $scope.SetSearchType = function(selection) {
    $scope.SearchType = selection.type;
  };

  $scope.SetSearchCondition = function(selection) {
    $scope.SearchCondition = selection.value;
  };

  $scope.AddNewSearchSection = function() {
    var newItemNo = $scope.searchSection.length + 1;
    $scope.searchSection.push({
      'id': 'section' + newItemNo
    });
  };

  $scope.RemoveSearchSection = function(section){
          var index = $scope.searchSection.indexOf(section);
        $scope.searchSection.splice(index, 1);
    };

  $scope.showAddAdditionalSearchParameters = function(section) {
    var index = $scope.searchSection.length - 1;
    console.log("compare "+section.id+" to "+$scope.searchSection[index].id);
    return section.id === $scope.searchSection[index].id;
  };

  $scope.SetSearchType($scope.chosenColumn);
  $scope.SetSearchCondition($scope.chosenStringCondition);
}]);

A:

I would personally use Date.now() for unique id on the section instead of array.length + 1. other better ways compare to this is always possible.
 $scope.AddNewSearchSection = function () {
    var newItemNo = Date.now().toString(); //$scope.searchSection.length + 1;
    $scope.searchSection.push({
        'id' : 'section' + newItemNo
    });
 };

 $scope.RemoveSearchSection = function (section) {
    var i;
    //index of section will not give you the correct answer
    //as noted already you want section.id part and compare with that
    //one way is to loop through the array and remove it using splice
    for (i = $scope.searchSection.length - 1; i >= 0; i -= 1) {
        if ($scope.searchSection[i].id == section.id) {
            console.log('removed ' + section.id)
            $scope.searchSection.splice(i, 1);
            break;
        }
    }
 };

