本文介绍了NG-Click不适用于Chrome,但适用于FireFox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个NG-Click来更改页面上的元素数量(来自API调用)。 NG-Click利用一个在FireFox中工作的下拉框。但是我最近发现,当同事开始使用这项服务时,它不适用于Chrome。我不知道为什么它不会工作,任何帮助表示赞赏。我附上了一个JSFidle的代码。

I have a NG-Click to change the amount of elements on the page (that are coming from an API call). The NG-Click utilizes a drop down box that works in FireFox. But I recently discovered that it isn't working in Chrome when a co-worker started working on the service. I have no idea as to why it wouldn't work and any help is appreciated. I've attached a JSFidle with the code.

JavaScript:

JavaScript:

app.controller("AppCtrl", function($http, $scope){
var app = this; 
$scope.toLoad=50;
$scope.page= 0;
$scope.sortArray = [];
$scope.filterList = "";

function getData(page){
    $http.get('/file/filter/' + $scope.toLoad + '/' + $scope.page + '?' + $scope.filterList ).success(function(data){
        app.info = data;
        console.log(data);
    });
}

$scope.changeLoad = function(toLoad){
    $scope.toLoad = toLoad;
    getData($scope.page)
}
}

HTML:

<body ng-app="app" ng-controller="AppCtrl as app" id="body">
<div id="main-table">

                <div class="widget-body no-padding">
                    <div id="select-more">
                        <select class="form-control" name="dt_basic_length" aria-controls="dt_basic" id="box-test" style="width:6%">
                            <option value="10" ng-click="changeLoad(10)"> 10 </option>
                            <option value="25" ng-click="changeLoad(25)"> 25 </option>
                            <option value="50" ng-click="changeLoad(50)"> 50 </option>
                            <option value="100" ng-click="changeLoad(100)"> 100 </option>
                            <option value="1000" ng-click="changeLoad(1000)"> 1000 </option>
                        </select>
                    </div>
                <table>
                    <tbody>
                            <tr ng-repeat="information in app.info | filter:searchText">
                                <td>{{information.uuid}}</td>
                                <td>{{information.publisher}}</td>
                                <td>{{information.ts}}</td>
                            </tr>
                        </tbody>
                    </table>
        </div>
  </div>               


推荐答案

您应该使用ng-change请参阅

You should use ng-change please see here

<body ng-app="app" ng-controller="AppCtrl" id="body">
<div id="main-table"> 

    <div class="widget-body no-padding">
        <div id="select-more">
            <select class="form-control" name="dt_basic_length" aria-controls="dt_basic" id="box-test" style="width:6%" ng-change="update()" ng-model="selectedItem">
                <option value="10">10</option>
                <option value="25">25</option>
                <option value="50">50</option>
                <option value="100">100</option>
                <option value="1000">1000</option>
            </select>
        </div>
        <table>
            <tbody>
                <tr ng-repeat="information in app.info | filter:searchText">
                    <td>{{information.uuid}}</td>
                    <td>{{information.publisher}}</td>
                    <td>{{information.ts}}</td>
                </tr>
            </tbody>
        </table>
    </div>
</div>

js:

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

app.controller("AppCtrl", function ($http, $scope) {
    var app = this;
    $scope.toLoad = 50;
    $scope.page = 0;
    $scope.sortArray = [];
    $scope.filterList = "";

    $scope.selectedItem = {};

    function getData(page) {
        $http.get('/file/filter/' + $scope.toLoad + '/' + $scope.page + '?' + $scope.filterList).success(function (data) {
            app.info = data;
            console.log(data);
        });
    }

    $scope.changeLoad = function (toLoad) {
        $scope.toLoad = toLoad;
        getData($scope.page);
    };

    $scope.update = function () {
      alert($scope.selectedItem);
    };
});

这篇关于NG-Click不适用于Chrome,但适用于FireFox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 05:24