angularjsangularjs-ng-repeatangularjs-select2

Remove Option dynamically From select box


api return status which is assign to $scope.status it come dynamically

$scope.status = [{"planStatus":"Completed","records":2},{"planStatus":"Partial","records":22},{"planStatus":"Active","records":24},{"planStatus":"Merged","records":6}]

This is my html code where i created select box using ng-repeat

<select ng-options="sta.planStatus as sta.planStatus for sta in status" ng-model="plan.planStatus"  class="form-control">
         <option class="selectoption" value="">Select Status</option>
</select>   

I am creating a select box, 5 option show in my select box
I want to remove one option(like Active) from html? How can i do it. it is possible to do without change api response


Solution

  • You can use angular filters to remove the options. To remove the option where planStatus is 'Active', try this.

    ng-options="sta.planStatus as sta.planStatus for sta in status | filter: optionsFilter"
    

    In Controller:

    $scope.optionsFilter = function (option) {
        if (option.planStatus == 'Active') {
            return false;
         }
        return true;
    }