角度下拉过滤无效

时间:2016-08-04 09:12:20

标签: javascript jquery angularjs laravel-5

  <div class="col-sm-3 col-md-3" data-ng-controller="LoginHistoryListVM" >
       <label class="col-sm-5 col-md-5 control-label">Company Name</label>
       <div class="col-sm-7 col-md-7">
            <select class="form-control" ng-model="name" ng-change="companynameSearch()" ng-options="obj.name for obj in companyname track by obj.name">
              <option value="">Select Company</option>
            </select>
            <input type="hidden" name="select_company_name" id="select_company_name" value="">
       </div>
  </div>

这是公司的垮台。

    <table class="rwd-table table table-striped table-hover" ng-table="LoginHistories.tableParams" show-filter="{{LoginHistories.filtered}}">
      <tr ng-repeat="loginhistory in $data | filter: name">
        <td data-title="'First Name'" sortable="'fname'" filter="{ 'fname': 'text' }">
        <!--<td data-title="'First Name'" sortable="'fname'" filter="{ 'fname': 'select' }" filter-data="uname($column)">-->
            <!-- <a ui-sref="loginHistoryShow({userId: loginhistory.id})">{{loginhistory.fname}}</a> -->
            {{loginhistory.fname}}
        </td>
        <td data-title="'Last Name'" sortable="'lname'" filter="{ 'lname': 'text' }">
            {{loginhistory.lname}}
        </td>
        <td data-title="'Compnay Name'" sortable="'name'" filter="{ 'name': 'text' }">
        <!--<td data-title="'Compnay Name'" sortable="'name'" filter="{ 'name': 'select' }" filter-data="cname($column)">-->
            {{loginhistory.name}}
        </td>
        <td data-title="'IP Address'" sortable="'ip_address'">
            {{loginhistory.ip_address}}
        </td>
        <td data-title="'Country'" sortable="'country'">
            {{loginhistory.country}}
        </td>
        <td data-title="'City'" sortable="'city'">
            {{loginhistory.city}}
        </td>
        <td data-title="'Logged On'" sortable="'created_at'">
          <span class="label label-primary">{{loginhistory.created_at.date | amDateFormat:'MMM Do YYYY, h:mm:ss a'}}</span>
        </td>
      </tr>
    </table>

这是控制器我添加了下拉功能companynameSearch我添加了当我选择下拉选项时出现错误,因为&#34;错误:设置。$ scope是null&#34;,所以请给我任何建议过滤器。

    function LoginHistoryListVM($filter, ngTableParams, LoginHistory,$stateParams ,$scope, $q) {
      this.filtered = true;
       $scope.tableParams = this.tableParams = new ngTableParams({
        page: 1,
        count: 10,
        filter:{
          name : $scope.name ? $scope.name.name : ''
        },
        sorting: {
          fname: 'asc'
        },
      }, {
        total: 0,
        getData: function ($defer, params) { 
          var page = params.page();
          var sort = params.sorting();
          var filter = params.filter(); 
          var opts = {
            page: page,
            companyID : $stateParams.companyID,
            orderBy: _.keys(sort)[0],
            direction: _.values(sort)[0],
            field: _.keys(filter)[0],
            term: _.values(filter)[0]
          };

          LoginHistory.remote.get(opts).$promise.then(function (res) {
            $scope.companyname = res.allcompanynames;
            var data = mapUserCompanyName(res.data.data);  
            var filteredData = params.filter() ? $filter('filter')(data, params.filter()) : data;
            var orderedData = params.sorting() ? $filter('orderBy')(filteredData, params.orderBy()) : data;
            params.total(res.data.total);
            $defer.resolve(orderedData);
          });
        }
      });

      $scope.companynameSearch = function () {
         var selectedcomnayname =  $scope.name.name;
         $('#select_company_name').val($scope.name.name);
         $scope.tableParams.reload();     
         //console.log($scope.ts.reload());
      };

      function mapUserCompanyName(data) {  
        return _.map(data, function (loginhistory) { 
          loginhistory.company = _.isObject(loginhistory.company) ? loginhistory.company.name : loginhistory.company;
          return loginhistory;
        });
      }
    }

1 个答案:

答案 0 :(得分:0)

这是最简单的例子,它工作正常。所以,请提供更多信息。

&#13;
&#13;
var app = angular.module('MyApp', []);

app.controller('AppCtrl', function($scope) {
    $scope.companyname = [ { name: 'Google'}, { name: 'IBM'}];
    $scope.selectedcomnayname = '';

    $scope.companynameSearch = function () {
        $scope.selectedcomnayname =  $scope.name.name;
    };
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.min.js"></script>

<div ng-controller="AppCtrl" ng-cloak="" ng-app="MyApp">
   <label class="col-sm-5 col-md-5 control-label">Company Name</label>
   <div class="col-sm-7 col-md-7">
       <select class="form-control" ng-model="name" ng-change="companynameSearch()" ng-options="obj.name for obj in companyname track by obj.name">
           <option value="">Select Company</option>
       </select>
       <br/>
       <span ng-bind="selectedcomnayname">
   </div>
</div>
&#13;
&#13;
&#13;