Angular Material下拉选择框


<pre><code class=”lang-html”><html lang = "en">
<head>
<link rel = "stylesheet"
href = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.css">
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-animate.min.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
<script src = "https://ajax.googleapis.com/ajax/libs/angular_material/1.0.0/angular-material.min.js"></script>
<link rel = "stylesheet" href = "https://fonts.googleapis.com/icon?family=Material+Icons">

<script language = "javascript">
angular
.module('firstApplication', ['ngMaterial'])
.controller('selectController', selectController);

function selectController ($scope) {
$scope.users = [
{ id: 1, name: 'Mahesh' },
{ id: 2, name: 'Ramesh' },
{ id: 3, name: 'Sohan' }
];

$scope.selectedUser = { id: 2, name: 'Ramesh' };
$scope.drinks = [
{ category: 'hard', name: 'Beer' },
{ category: 'hard', name: 'Rum' },
{ category: 'hard', name: 'Vodka' },
{ category: 'hard', name: 'Whiski' },
{ category: 'soft', name: 'Coke' },
{ category: 'soft', name: 'Pepsi' },
{ category: 'soft', name: 'Pulp Maid' },
{ category: 'soft', name: 'Real Juice' }
];
}
</script>
</head>

<body ng-app = "firstApplication">
<div id = "selectContainer" ng-controller = "selectController as ctrl"
layout = "row" ng-cloak>
<md-input-container>
<label>User</label>
<md-select ng-model = "selectedUser">
<md-option ng-value = "user"
ng-repeat = "user in users">{{ user.name }}</md-option>
</md-select>
</md-input-container>

<md-input-container>
<label>Drinks</label>
<md-select ng-model = "drink">
<md-optgroup label = "Hard Drinks">
<md-option ng-value = "drink.name"
ng-repeat = "drink in drinks | filter: {category: 'hard' }">
{{drink.name}}</md-option>
</md-optgroup>

<md-optgroup label = "Soft Drinks">
<md-option ng-value = "drink.name"
ng-repeat = "drink in drinks | filter: {category: 'soft' }">
{{drink.name}}</md-option>
</md-optgroup>
</md-select>
</md-input-container>

</div>
</body>
</html>
</code></pre>

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/264598.html

(0)
上一篇 2022年6月7日 14:14
下一篇 2022年6月7日 14:18

相关推荐

发表回复

登录后才能评论