- Angular Material 教程
- Angular Material - 首页
- Angular Material - 概述
- 环境搭建
- Angular Material - 自动完成
- Angular Material - 底部表单
- Angular Material - 卡片
- Angular Material - 小部件
- Angular Material - 布局
- Angular Material - 输入框
- Angular Material - 图标
- Angular Material - 网格
- Angular Material - 侧边导航栏
- Angular Material - 浮动操作按钮速拨盘
- Angular Material - 副标题
- Angular Material - 滑动
- Angular Material - 开关
- Angular Material - 主题
- Angular Material - 提示信息
- Angular Material - 排版
- Angular Material - 虚拟滚动
- Angular Material - 白框
- Angular Material 有用资源
- Angular Material - 快速指南
- Angular Material - 有用资源
- Angular Material - 讨论
Angular Material - 环境搭建
如何使用 Angular Material?
有两种方法可以使用 Angular Material:
本地安装 - 你可以使用 npm、jspm 或 bower 在本地机器上下载 Angular Material 库,并将其包含在你的 HTML 代码中。
基于 CDN 的版本 - 你可以直接从内容分发网络 (CDN) 将 angular-material.min.css 和 angular-material.js 文件包含到你的 HTML 代码中。
本地安装
在我们使用以下 npm 命令之前,需要在系统上安装 NodeJS。要获取有关 NodeJS 的信息,请点击 这里 并打开 NodeJS 命令行界面。我们将使用以下命令安装 Angular Material 库。
npm install angular-material
以上命令将生成以下输出:
[email protected] node_modules\angular-animate [email protected] node_modules\angular-aria [email protected] node_modules\angular-messages [email protected] node_modules\angular [email protected] node_modules\angular-material
npm 将在 node_modules > angular-material 文件夹下下载文件。按照以下示例中的说明包含这些文件:
示例
现在,你可以按照如下方式将 css 和 js 文件包含在你的 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> <script type = "text/javascript"> angular.module('firstApplication', ['ngMaterial']); </script> </head> <body ng-app = "firstApplication" ng-cloak> <md-toolbar class = "md-warn"> <div class = "md-toolbar-tools"> <h2 class = "md-flex">HTML 5</h2> </div> </md-toolbar> <md-content flex layout-padding> <p>HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML 1.0, and XHTML 1.1. HTML5 is a standard for structuring and presenting content on the World Wide Web.</p> <p>HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web Hypertext Application Technology Working Group (WHATWG).</p> <p>The new standard incorporates features like video playback and drag-and-drop that have been previously dependent on third-party browser plug-ins such as Adobe Flash, Microsoft Silverlight, and Google Gears.</p> </md-content> </body> </html>
以上程序将生成以下结果:
基于 CDN 的版本
你可以直接从内容分发网络 (CDN) 将 angular-material.css 和 angular-material.js 文件包含到你的 HTML 代码中。Google CDN 提供最新版本的內容。
在本教程中,我们始终使用 Google CDN 版本的库。
示例
现在让我们使用来自 Google CDN 的 angular-material.min.css 和 angular-material.min.js 重写上面的示例。
<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> <script type = "text/javascript"> angular.module('firstApplication', ['ngMaterial']); </script> </head> <body ng-app = "firstApplication" ng-cloak> <md-toolbar class = "md-warn"> <div class = "md-toolbar-tools"> <h2 class = "md-flex">HTML 5</h2> </div> </md-toolbar> <md-content flex layout-padding> <p>HTML5 is the next major revision of the HTML standard superseding HTML 4.01, XHTML 1.0, and XHTML 1.1. HTML5 is a standard for structuring and presenting content on the World Wide Web.</p> <p>HTML5 is a cooperation between the World Wide Web Consortium (W3C) and the Web ypertext Application Technology Working Group (WHATWG).</p> <p>The new standard incorporates features like video playback and drag-and-drop that have been previously dependent on third-party browser plug-ins such as Adobe Flash, Microsoft Silverlight, and Google Gears.</p> </md-content> </body> </html>
以上程序将生成以下结果:
广告