jeudi 5 janvier 2017

AngularJS multiple checkbox filter is not working properly?

There is a list of employee array, i have to apply the multiple checkbox filter,it is working in the only 1 checkbox it is displayed properly,but in case of multiple properly it is not properly work,how to fix this?

//here we crate the module for the CRUD application here    
var app= angular.module("myApp",[]);
app.controller("myCont", function($scope,myService){

        //here we create the myService function for show the Dmmt array 
       $scope.user = myService.show();
       console.log($scope.user);

       //here we create the saveUser function for push the item into the list
                $scope.saveUser = function(){
                        var data = 
                                        {
                                                eid:$scope.user.eid,
                                                email:$scope.user.email,
                                                city:$scope.user.city,
                                                salary:$scope.user.salary,
                                                date:$scope.user.date,
                                        }       
                        //here we create will pass the user data to the myService of the show2 
                         $scope.user =myService.show2(data);
                }

                //here we delete the deleteUser function for remove  the item into the lsit
                $scope.deleteUser = function(index){
                                $scope.result3 =myService.show3(index);
                                 console.log($scope.result3);

                        }//close contrller here

                        $scope.editeUser = function(x){
                                $scope.ok= myService.editeUsers(x);


                        }
});



-----Declare the service code:--
//her e we crete the myService function in which we declare the static that will be display in the 
//index.html page
app.service("myService",function(){

        var employee =[];
        var clickedUser =" "; 
        var message="";

        //here we create the show function for declare dynamic array & display in the home page of the user
        this.show = function(){
                employee =
                 [

                        {
                                eid:"Harry Potter",
                                email:"harry@yahoo.com",
                                salary:12000,
                                city:"Australia",
                                date:"2014-10-19"
                                            },
                    {
                                eid:"Peter Potter",
                                email:"harry@yahoo.com",
                                salary:5000,
                                city:"Ghosala",
                                date:"2014-10-28"
                                            },
                    {
                                eid:"Gotm Potter",
                                email:"harry@yahoo.com",
                                salary:2000,
                                city:"Bhopal",
                                date:"2014-10-24"
                                
                   },
                                        {
                                eid:"Harry Potter",
                                email:"harry@yahoo.com",
                                salary:12000,
                                city:"Australia",
                                date:"2014-10-29"
                                            },
                    {
                                eid:"Peter Potter",
                                email:"harry@yahoo.com",
                                salary:5000,
                                city:"Harmaini",
                                date:"2014-10-10"
                                            },
                    {
                                eid:"Gotm Potter",
                                email:"harry@yahoo.com",
                                salary:2000,
                                city:"Playboy",
                                date:"2014-10-03"
                                
                   },


                                                 ]
                 return employee;

        }

        //here we create the show2 function that will be received our data from the contoller
        //& the push into the array of the employee
        this.show2 = function(data){
                employee.push(data);
                message="push ho gy";
                return employee;
        }

        //here we create the show3  function that will be remove user from the list
        //& through the index of the list
        this.show3 = function(index){
                employee.splice(index,1);
                message="deleted ho gya bhai re mere";
        }

        this.editeUsers = function(x){
                var clickedUser =x;
        }
}

);
<!DOCTYPE html>
<html lang="en">
  <head>
    
      <link href="css/bootstrap.min.css" rel="stylesheet">
      <!-- include the angularjs files here-->
      <script src="js/angular.min.js"></script>
       <script src="http://ift.tt/1XwG72U"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="js/bootstrap.min.js"></script>
      <script src="app/controller.js"></script>
      <script src="app/service.js"></script>
      
      <script src="http://ift.tt/1XwG72U"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="js/bootstrap.min.js"></script>
  </head>
<body  ng-app="myApp" ng-controller="myCont">
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span> 
      </button>
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">Page 1</a></li>
        <li><a href="#">Page 2</a></li> 
        <li><a href="#">Page 3</a></li> 
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="hello.html"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>
    <button type="button" class="btn btn-info btn-lg pull-right" data-toggle="modal" data-target="#myModal">Add New User</button>

          <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'Bhopal'" data-ng-false-value=''/>Bhopal
      <br>
       <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'Australia'" data-ng-false-value=''/> Australia<br>

      <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'Playboy'" data-ng-false-value=''/>Playboy
      <br>
       <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'London'" data-ng-false-value=''/>London<br>


    <div class="container">
    <div class="jumbotron">
          
              Emp Here<input type="text" ng-model="search" placeholder="Emp Serch.."> </input>
        <span class="clearfix">
        </span>
      
      <div class="alert alert-info" ng-if="message">
          Info  <a href="#" class="close" ng-click="clear()">&times;</a>.
      </div>
      <table class="table table-hover">
        <thead>
          <tr>
                <th>EmployeenName</th>
                <th>Email</th>
                <th>Salary</th>
                <th>City</th>
                
                <th>Date</th>
          </tr>
        </thead>
        <tbody>
           <tr ng-repeat="x in user |filter:search | filter:ok.type1 | orderBy:'city' ">
                <td></td>
                <td> </td>
                <td></td>
                <td></td>
                <td></td>

          <td>
              <button type="button"  class="btn btn-info" ng-click="isEditForm=true;">edit</button>
           </td>
           <td ng-show="isEditForm">
            <lable>Name</label><input ng-model="x.eid"/><br>
            <lable>Email</label><input ng-model="x.email"/><br>
            <lable>salary</label><input ng-model="x.salary"/><br>
            <lable>city</label><input ng-model="x.city"/><br>
              <button ng-click="isEditForm=false;">SAVE HERE</button>

           </td>
          <td>
              <button type="button" class="btn btn-success"   data-toggle="modal" data-target="#myModalDelete">Delete</button>
          </td>
        </tr>
        </tbody>
      </table>
      <!-- Modal -->
      <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">
        <!-- Modal content-->

          <div class="modal-content">
            <div class="modal-body">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">New User Registration</h4>
           </div>
               

               <div class="form-group">
                 <label class="control-label col-sm-2">Name</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="eid" ng-model="user.eid" placeholder="Enter Name">
                  </div>
              </div>
              <div class="form-group">
                 <label class="control-label col-sm-2">Email</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="email" ng-model="user.email" placeholder="Enter Email">
                  </div>
              </div>
              <div class="form-group">
                 <label class="control-label col-sm-2">City</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="city" ng-model="user.city" placeholder="Enter city">
                  </div>
              </div>
              <div class="form-group">
                 <label class="control-label col-sm-2">Salary</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="salary" ng-model="user.salary" placeholder="Enter salary">
                  </div>
              </div>
                       <div class="form-group">
                 <label class="control-label col-sm-2">Date</label>
                   <div class="col-sm-10">
                         <input type="date" class="form-control" name="date" ng-model="user.date" placeholder="Enter date">
                  </div>
              </div>

                </div>
          <div class="form-group"> 
              <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default"  data-dismiss="modal"
                ng-click="saveUser()" >Submit</button>
                    </div>
                </div>
                   <div class="modal-footer">
                  </div>
                </div>
              </form>
            </div> <!-- here model body is closed-->
          </div> <!-- here model content is clo  sed-->
        </div>
      </div>
      <!-- Declare another model is declare for edit Modal -->

      


      <!--Here we creat the delete user model for dlete the user -->
      <div class="modal fade" id="myModalDelete" role="dialog">
         <div class="modal-dialog">
            <div class="modal-content">
                 <div class="modal-header"> 
                      <button type="button" class="close" data-dismiss="modal">&times;
                      </button>
                      <h4 class="modal-title">Are R Want to Delete </h4>
                  </div>
                    <div class="modal-body">
                        <strong style="color:blue;">
                          You re going to delete the usernme</strong>
                      </h4>
                </div>
                 
                   <style type="text/css"></style>
                       <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="deleteUser($index)">Yes
                            </button>
                           <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
                    </div>
               </div> <!-- here model body is closed-->
          </div> <!-- here model content is closed-->
        </div>
      </div>
    </div>
    </div>
    </
  </form>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
   <script src="http://ift.tt/1XwG72U"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>
<!DOCTYPE html>
<html lang="en">
  <head>
    
      <link href="css/bootstrap.min.css" rel="stylesheet">
      <!-- include the angularjs files here-->
      <script src="js/angular.min.js"></script>
       <script src="http://ift.tt/1XwG72U"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="js/bootstrap.min.js"></script>
      <script src="app/controller.js"></script>
      <script src="app/service.js"></script>
      
      <script src="http://ift.tt/1XwG72U"></script>
      <!-- Include all compiled plugins (below), or include individual files as needed -->
      <script src="js/bootstrap.min.js"></script>
  </head>
<body  ng-app="myApp" ng-controller="myCont">
<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span> 
      </button>
      <a class="navbar-brand" href="#">WebSiteName</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#">Home</a></li>
        <li><a href="#">Page 1</a></li>
        <li><a href="#">Page 2</a></li> 
        <li><a href="#">Page 3</a></li> 
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="hello.html"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>
    <button type="button" class="btn btn-info btn-lg pull-right" data-toggle="modal" data-target="#myModal">Add New User</button>

          <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'Bhopal'" data-ng-false-value=''/>Bhopal
      <br>
       <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'Australia'" data-ng-false-value=''/> Australia<br>

      <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'Playboy'" data-ng-false-value=''/>Playboy
      <br>
       <input type="checkbox" data-ng-model='ok.type1' data-ng-true-value="'London'" data-ng-false-value=''/>London<br>


    <div class="container">
    <div class="jumbotron">
          
              Emp Here<input type="text" ng-model="search" placeholder="Emp Serch.."> </input>
        <span class="clearfix">
        </span>
      
      <div class="alert alert-info" ng-if="message">
          Info  <a href="#" class="close" ng-click="clear()">&times;</a>.
      </div>
      <table class="table table-hover">
        <thead>
          <tr>
                <th>EmployeenName</th>
                <th>Email</th>
                <th>Salary</th>
                <th>City</th>
                
                <th>Date</th>
          </tr>
        </thead>
        <tbody>
           <tr ng-repeat="x in user |filter:search | filter:ok.type1 | orderBy:'city' ">
                <td></td>
                <td> </td>
                <td></td>
                <td></td>
                <td></td>

          <td>
              <button type="button"  class="btn btn-info" ng-click="isEditForm=true;">edit</button>
           </td>
           <td ng-show="isEditForm">
            <lable>Name</label><input ng-model="x.eid"/><br>
            <lable>Email</label><input ng-model="x.email"/><br>
            <lable>salary</label><input ng-model="x.salary"/><br>
            <lable>city</label><input ng-model="x.city"/><br>
              <button ng-click="isEditForm=false;">SAVE HERE</button>

           </td>
          <td>
              <button type="button" class="btn btn-success"   data-toggle="modal" data-target="#myModalDelete">Delete</button>
          </td>
        </tr>
        </tbody>
      </table>
      <!-- Modal -->
      <div class="modal fade" id="myModal" role="dialog">
        <div class="modal-dialog">
        <!-- Modal content-->

          <div class="modal-content">
            <div class="modal-body">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">New User Registration</h4>
           </div>
               

               <div class="form-group">
                 <label class="control-label col-sm-2">Name</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="eid" ng-model="user.eid" placeholder="Enter Name">
                  </div>
              </div>
              <div class="form-group">
                 <label class="control-label col-sm-2">Email</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="email" ng-model="user.email" placeholder="Enter Email">
                  </div>
              </div>
              <div class="form-group">
                 <label class="control-label col-sm-2">City</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="city" ng-model="user.city" placeholder="Enter city">
                  </div>
              </div>
              <div class="form-group">
                 <label class="control-label col-sm-2">Salary</label>
                   <div class="col-sm-10">
                         <input type="text" class="form-control" name="salary" ng-model="user.salary" placeholder="Enter salary">
                  </div>
              </div>
                       <div class="form-group">
                 <label class="control-label col-sm-2">Date</label>
                   <div class="col-sm-10">
                         <input type="date" class="form-control" name="date" ng-model="user.date" placeholder="Enter date">
                  </div>
              </div>

                </div>
          <div class="form-group"> 
              <div class="col-sm-offset-2 col-sm-10">
                        <button type="submit" class="btn btn-default"  data-dismiss="modal"
                ng-click="saveUser()" >Submit</button>
                    </div>
                </div>
                   <div class="modal-footer">
                  </div>
                </div>
              </form>
            </div> <!-- here model body is closed-->
          </div> <!-- here model content is clo  sed-->
        </div>
      </div>
      <!-- Declare another model is declare for edit Modal -->

      


      <!--Here we creat the delete user model for dlete the user -->
      <div class="modal fade" id="myModalDelete" role="dialog">
         <div class="modal-dialog">
            <div class="modal-content">
                 <div class="modal-header"> 
                      <button type="button" class="close" data-dismiss="modal">&times;
                      </button>
                      <h4 class="modal-title">Are R Want to Delete </h4>
                  </div>
                    <div class="modal-body">
                        <strong style="color:blue;">
                          You re going to delete the usernme</strong>
                      </h4>
                </div>
                 
                   <style type="text/css"></style>
                       <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal" ng-click="deleteUser($index)">Yes
                            </button>
                           <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
                    </div>
               </div> <!-- here model body is closed-->
          </div> <!-- here model content is closed-->
        </div>
      </div>
    </div>
    </div>
    </
  </form>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
   <script src="http://ift.tt/1XwG72U"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
  </body>
</html>
enter code here




Aucun commentaire:

Enregistrer un commentaire