加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS表不工作

发布时间:2020-12-17 07:45:08 所属栏目:安全 来源:网络整理
导读:手表不工作 我包含以下内容: form class="search" div class="searchbar" input type="search" value="" data-ng-model="searchKeyword" placeholder="zoeken" button type="submit"i class="glyphicon glyphicon-search"/i/button /div/form 喜欢这个: di
手表不工作
我包含以下内容:
<form class="search">
    <div class="searchbar">
        <input type="search" value="" data-ng-model="searchKeyword" placeholder="zoeken">
        <button type="submit"><i class="glyphicon glyphicon-search"></i></button>
    </div>
</form>

喜欢这个:

<div ng-include src="filterPath" onload="initiateSearch()"></div>

onload函数是这样做的:

(function(){
    var appController = angular.module('ListerAppController',[]);

    appController.controller('ListerCtrl',['$scope','$rootScope','$http','$filter','$timeout','$sharedFactories','History','$location',function($scope,$rootScope,$http,$filter,$timeout,$sharedFactories,History,$location) {
            $scope.initiateSearch = function () {
            // This is what you will bind the filter to
                $scope.filterText = '';

                // Instantiate these variables outside the watch
                var tempFilterText = '',filterTextTimeout;

                $scope.$watch('searchKeyword',function (val) {
                    if (filterTextTimeout) $timeout.cancel(filterTextTimeout);

                    tempFilterText = val;

                    filterTextTimeout = $timeout(function() {
                        $scope.filterText = tempFilterText;
                        $scope.pageCount = function() {
                            return Math.ceil( $scope.itemsfiltered.length / $scope.itemsPerPage );
                    };
                },350); // delay 250 ms
            });
        };
    }]);
})();

一切似乎都会好转,但是…在$watch on searchKeyword当我开始输入名为searchKeyword的输入元素时,从来不会激活这个功能.

该手表必须是对象的属性,而不是对象本身,请参阅此处的示例 https://docs.angularjs.org/api/ng/type/ $rootScope.Scope如何添加手表,并使用模型此处为 https://docs.angularjs.org/api/ng/directive/input.
你可以尝试这个(我没有测试过)
data-ng-model="search.keyword"

并在你的控制器:

$scope.search = {}

$scope.$watch('search.keyword',...

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读