繁体   English   中英

不会出现Angular UI typeahead下拉列表

[英]Angular UI typeahead drop down does not appear

我正在使用Angular UI的typeahead与Web Api结合来加载搜索结果。 My Angular是版本1.2.2,bootstrap是3.1.0。 我应该提一下,我也在使用打字稿。

当我在搜索框中输入时,我希望下拉菜单中包含从输入中删除的建议。 当我检查控制台时,我看到了我的返回数据,问题是没有下拉菜单出现显示它。

这是我的HTML +角度指令:

<div class="input-group">
                <input type="text" class="form-control" placeholder="Search" ng-model="selected"
                       data-typeahead="searchResult as searchResult for searchResult in search($viewValue) | filter:$viewValue" >
                <div class="input-group-btn">
                    <button class="btn btn-default" type="submit" ng-click="search(Text)"><i class=" glyphicon glyphicon-search"></i></button>
                </div>
            </div>

这是我的控制器中的js函数:

$scope.search = function (criteria) {
                    controller.dataService.search($scope.employeeId, criteria, function (data) {
                        $scope.searchResult = data;
                });

这是我的数据服务中的搜索功能。

export interface ICommonDataService extends IBaseDataService {
    search(employeeId: string, criteria: string, successCallback: (data: SearchResult) => any);
}

dataservice.ts信息:

export class DataServicBase {
    public httpService: ng.IHttpService;
    public serviceBase = '/services/api';

    public static $inject = [
        '$http'
    ];

    constructor($http: any) {
        this.httpService = $http;
    }
}

    export class CommonDataService extends DataServicBase implements ICommonDataService {
    public serviceUrl = this.serviceBase + '/common';

    search(employeeId: string, criteria: string, successCallback: (data: SearchResult) => any) {
        this.httpService.get(this.serviceUrl + '/' + employeeId + '/search/' + criteria)
            .success(function (data) {
                successCallback(data);
            });
    }
}

这就是SearchResult的样子:

// Class
export class SearchResult {
    // Constructor
    constructor(
        public Employees: Employee[],
        public Filters: Employee[],
        public Projects: Project[]
        ) {
    }
}

我得到的错误是这样的:

Error: matches is undefined
.link/getMatchesAsync/<@https://web.plank.local/Scripts/ui-bootstrap-tpls-0.10.0.js:3186
qFactory/defer/deferred.promise.then/wrappedCallback@https://web.plank.local/scripts/angular.js:10655
qFactory/defer/deferred.promise.then/wrappedCallback@https://web.plank.local/scripts/angular.js:10655
qFactory/ref/<.then/<@https://web.plank.local/scripts/angular.js:10741
$RootScopeProvider/this.$get</Scope.prototype.$eval@https://web.plank.local/scripts/angular.js:11634
$RootScopeProvider/this.$get</Scope.prototype.$digest@https://web.plank.local/scripts/angular.js:11479
$RootScopeProvider/this.$get</Scope.prototype.$apply@https://web.plank.local/scripts/angular.js:11740
textInputType/listener@https://web.plank.local/scripts/angular.js:15739
jQuery.event.dispatch@https://web.plank.local/scripts/jquery-2.1.0.js:4371
jQuery.event.add/elemData.handle@https://web.plank.local/scripts/jquery-2.1.0.js:4057
aM@https://cdn.qbaka.net/reporting.js:78

https://web.plank.local/scripts/angular.js
Line 9159

主要问题是您希望输入的数据列表不是列表(或未填充)。 在我看来,你在控制器中的函数搜索应该返回数据,而它只是一个承诺。 您可以尝试返回 数据 ,并使其更加健壮,您可以添加limitToFilter 而不是将它放在共享的scope.searchResult中,而你的先行者根本没有把它取出。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM