我正在使用Angular v1.3.0-beta.17
这是错误:我不知道造成这种情况的原因。有人说它是因为控制器没有使用承诺。其他人说它是弃用的ng-bind-html-unsafe指令。我已阅读添加ng-Sanitize修复此问题。它没有。我读了一篇帖子说这个最新版本的角度修复了这个错误。我已升级到此预发行版,但仍然出现错误。数据从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)
预输入-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>
预输入-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;
});
};