angularjsangular-ngmodelangularjs-ng-optionsangularjs-select

how to select table view pending by default


HTML

<select class="form-control" id="selectrequest" ng-model="selected request" ng-change="vm.selected_requested()">
    <option value="pending" > Pending </option>
    <option value="approved"> Approved </option>
    <option value="rejected"> Rejected </option>
</select>

JS

vm.model=[{
    name:'abc',
    lastname:'xyz',
    status:pending
}]

//need to select pending items by default vm.selected_requested = function (){

}

Solution

  • Hi I have implemented this functionality as you requested. Now you can see the samples of filtering from view as well from controller. Let me know if you need any further help

      var mainApp = angular.module("mainApp", []); 
           mainApp.controller('studentController', function($scope,filterFilter) {
            var vm = $scope;
             $scope.model=[{ name:'abc_pending', lastname:'xyz', status:"pending" },
                         { name:'abc1_pending', lastname:'xyz', status:"pending" },
                         { name:'abc2_approved', lastname:'xyz', status:"approved" },
                         { name:'abc3_rejected', lastname:'xyz', status:"rejected" }];   
             
             vm.filteredArray = []; 
             vm.selected_requested = function (){
               vm.filteredArray = filterFilter($scope.model, {status:$scope.selected_request});
            
             }
              });
    <html>
       
       <head>
          <title>Angular JS Controller</title>
          <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
       </head>
       
       <body>
          <h2>AngularJS Sample Application</h2>
          
          <div ng-app = "mainApp" ng-controller = "studentController">
            <select class="form-control" id="selectrequest" ng-model="selected_request" ng-change="selected_requested()">
                        <option value="" > All </option>
                        <option value="pending" > Pending </option>
                        <option value="approved"> Approved </option>
                        <option value="rejected"> Rejected </option>
                    </select> 
            <div ng-repeat = "temp in model | filter:(!!selected_request || undefined) && {status: selected_request} ">
               <span ng-bind ="temp.name">
                 </span>
               </div>
            <br/>
           Items in filtered Array <br/>
         <div ng-repeat = "temp in filteredArray">
               <span ng-bind ="temp.name">
                 </span>
               </div>
          </div> 
          
       </body>
    </html>