我正在试用角度材料设计,我无法显示md-autocomplete。
我已包含在我现有的项目中:
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/angular_material/0.7.0/angular-material.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.4/hammer.js"></script>
<!-- Angular Material Dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-animate.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular-aria.js"></script>
var storeApp = angular.module(
'AngularStore', ['ui.router', 'ngMaterial',...])
.config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('auth.autocomplete', {
url: '/autocomplete',
templateUrl: 'resources/partials/autocomplete.html',
controller: autocompleteCtrl,
});
}]);
和autocomplete.html:
<div layout="column">
<md-content class="md-padding" layout="column" style="min-height: 200px; padding-top: 50px;">
<md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="display" placeholder="Search...">
<span md-highlight-text="searchText">{{item.display}}</span>
</md-autocomplete>
</md-content>
</div>
我的控制器是空的:
function autocompleteCtrl($scope){
}
生成的html是:
<md-content class="md-padding md-default-theme" layout="column" style="min-height: 200px; padding-top: 50px;">
<md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="display" placeholder="Search...">
<span md-highlight-text="searchText" class="ng-binding"></span>
</md-autocomplete>
</md-content>
在演示页面上:
<md-autocomplete md-selected-item="selectedItem" md-search-text="searchText" md-items="item in getMatches(searchText)" md-item-text="display" placeholder="Search..." class="ng-isolate-scope"> <md-autocomplete-wrap role="listbox"> <input type="text" ng-disabled="isDisabled" ng-model="searchText" ng-keydown="$mdAutocompleteCtrl.keydown($event)" ng-blur="$mdAutocompleteCtrl.blur()" placeholder="Search..." aria-label="Search..." aria-autocomplete="list" aria-haspopup="true" aria-activedescendant="" aria-expanded="false" class="ng-valid ng-dirty ng-valid-parse ng-touched" aria-owns="ul_001" tabindex="0" aria-invalid="false"> <!-- ngIf: searchText --> <!-- ngIf: $mdAutocompleteCtrl.loading --> </md-autocomplete-wrap> <ul role="presentation" id="ul_001"> <!-- ngRepeat: (index, item) in $mdAutocompleteCtrl.matches --> </ul> <aria-status class="visually-hidden" role="status" aria-live="assertive"> <!-- ngRepeat: message in $mdAutocompleteCtrl.messages --> </aria-status></md-autocomplete>
在我的项目中,我也使用bootstrap和jquery。
感谢。
答案 0 :(得分:1)
检查您正在使用的angular_material的版本。我认为自动完成功能仅适用于&gt; 0.8,而不是0.7.0(您正在使用)。另外,在你的帖子中,我看不到对angular-material.min.js文件的引用。您可能会将其包含在其他地方,只需检查。
希望有所帮助
答案 1 :(得分:0)
您可以尝试替换此行代码:
md-item-text="display"
为此:
md-item-text="item.display"
希望这会有所帮助..