Angular Material - 列表小部件
md-list 是一个 Angular 指令,它是一个容器组件,其中包含 md-list-item 元素作为子元素。 md-list-item 指令是 md-list 容器的行项目的容器组件。 CSS 类 md-2-line 和 md-3-line 可以添加到 md-list-item 中,以分别增加行高 22px 和 40px。
示例
以下示例显示了 md-list 指令的使用以及列表的使用。
am_lists.html
<html lang = "en"> <head> <link rel = "stylesheet" href = "https://www.w3ccoo.com/lib/angular_material/1.0.0/angular-material.min.css"> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular.min.js"></script> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular-animate.min.js"></script> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular-aria.min.js"></script> <script src = "https://cdn.staticfile.org/angular.js/1.4.8/angular-messages.min.js"></script> <script src = "https://www.w3ccoo.com/lib/angular_material/1.0.0/angular-material.min.js"></script> <script language = "javascript"> angular .module('firstApplication', ['ngMaterial']) .controller('listController', listController); function listController ($scope) { var self = this; self.allContacts = loadContacts(); self.contacts = [self.allContacts[0]]; function loadContacts() { var contacts = [ 'Roberto Karlos', 'Bob Crestor', 'Nigel Rick', 'Narayana Garner' ]; return contacts.map(function (c, index) { var cParts = c.split(' '); var contact = { name: c, email: cParts[0][0].toLowerCase() + '.' + cParts[1].toLowerCase() + '@example.com', image: 'http://lorempixel.com/50/50/people?' + index }; contact._lowername = contact.name.toLowerCase(); return contact; }); } } </script> </head> <body ng-app = "firstApplication"> <div id = "listContainer" ng-controller = "listController as ctrl" layout = "column" ng-cloak> <md-content> <md-list> <md-subheader class = "md-no-sticky">Contacts</md-subheader> <md-list-item class = "md-2-line contact-item" ng-repeat = "(index, contact) in ctrl.allContacts" ng-if = "ctrl.contacts.indexOf(contact) < 0"> <img ng-src = "{{contact.image}}" class = "md-avatar" alt = "{{contact.name}}" /> <div class = "md-list-item-text compact"> <h3>{{contact.name}}</h3> <p>{{contact.email}}</p> </div> <md-divider ng-if = "!$last"></md-divider> </md-list-item> </md-list> <md-list> <md-subheader class = "md-no-sticky">Contacts (With Insets)</md-subheader> <md-list-item class = "md-2-line contact-item" ng-repeat = "(index, contact) in ctrl.allContacts" ng-if = "ctrl.contacts.indexOf(contact) < 0"> <img ng-src = "{{contact.image}}" class = "md-avatar" alt = "{{contact.name}}" /> <div class = "md-list-item-text compact"> <h3>{{contact.name}}</h3> <p>{{contact.email}}</p> </div> <md-divider md-inset ng-if = "!$last"></md-divider> </md-list-item> </md-list> </md-content> </div> </body> </html>
结果
验证结果。
❮ angular_material_widgets.html