AngularJS表不工作

前端之家收集整理的这篇文章主要介绍了AngularJS表不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
手表不工作
我包含以下内容
<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>

喜欢这个:@H_502_5@

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

onload函数是这样做的:@H_502_5@

(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的输入元素时,从来不会激活这个功能.@H_502_5@

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

并在你的控制器:@H_502_5@

$scope.search = {}

…@H_502_5@

$scope.$watch('search.keyword',...
原文链接:https://www.f2er.com/angularjs/143001.html

猜你在找的Angularjs相关文章