1

我正在使用 Angular v1.3.0-beta.17

这是错误:我不知道是什么原因造成的。有人说这是因为控制器没有使用承诺。其他人说这是已弃用的 ng-bind-html-unsafe 指令。我已阅读添加 ng-Sanitize 修复此问题。它没有。我读了一篇文章说这个最新版本的 Angular 修复了错误。我已升级到此预发行版,但仍然收到错误消息。数据从 Web API 返回,但 ui-bootstrap typeahead 继续抛出此错误,并且不显示任何弹出窗口。

TypeError: Cannot read property 'length' of undefined
at http://localhost:7812/scripts/angular-ui/ui-bootstrap-tpls.min.js:9:13395
at L (http://localhost:7812/scripts/angular.min.js:100:156)
at L (http://localhost:7812/scripts/angular.min.js:100:156)
at http://localhost:7812/scripts/angular.min.js:101:321
at g.$eval (http://localhost:7812/scripts/angular.min.js:112:390)
at g.$digest (http://localhost:7812/scripts/angular.min.js:109:503)
at g.$delegate.__proto__.$digest (<anonymous>:844:31)
at g.$apply (http://localhost:7812/scripts/angular.min.js:113:208)
at g.$delegate.__proto__.$apply (<anonymous>:855:30)
at s (http://localhost:7812/scripts/angular.min.js:73:495) 

typeahead-popup.html

<ul class="autocomplete dropdown-menu" ng-style="{display: isOpen()&&'block' || 'none', top: position.top+'px', left: position.left+'px'}">
<li ng-repeat="match in matches" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index)">
    <typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></typeahead-match>
</li>

typeahead-match.html

<a tabindex="-1" bind-html-unsafe="match.label | typeaheadHighlight:query"></a>

我找到了错误的原因:这是控制器代码中的错误:

 $scope.getComplexes = function ($viewValue) {

    return $http.get('http://localhost:7802/api/Complexes/' + $viewValue)

        .then(function ($response) {
            console.log($response);
            angular.forEach($response.data.results, function (item) {
                complexes.push(item.Name);
            });                
        }); 
return complexes;      
};

.... 本来应该

 $scope.getComplexes = function ($viewValue) {

    return $http.get('http://localhost:7802/api/Complexes/' + $viewValue)

        .then(function ($response) {
            console.log($response);
            angular.forEach($response.data.results, function (item) {
                complexes.push(item.Name);
            });
            return complexes;
        });       
};
4

0 回答 0