角度材料缺少css类

时间:2014-10-30 12:31:02

标签: css angularjs material-design

我刚开始使用棱角分明的材料。我已经下载并引用了所有文件作为here上的使用说明。然后从here复制所有html代码以试用按钮。我得到了大部分工作,包括点击动画,但它没有任何主题,如md-primary。这就是我得到的。

enter image description here

我引用了angular-material.css,但我找不到md-primary或其中的任何css类。我缺少什么参考或如何为角材料创建那些CSS类?这就是它在演示页面上的样子。

enter image description here

我的代码示例。

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />    
<link href="../bower_components/angular-material/angular-material.css" rel="stylesheet" />
<link href="style.css" rel="stylesheet" />
</head>
<body ng-app="YourApp">

<div ng-controller="YourController">
    <md-content>

        <section layout="vertical" layout-sm="horizontal" layout-align="center center">
            <md-button>Button</md-button>
            <md-button noink class="md-primary">Primary (noink)</md-button>
            <md-button disabled class="md-primary">Disabled</md-button>
            <md-button class="md-warn">Warn</md-button>
            <div class="label">flat</div>
        </section>

        <section layout="vertical" layout-sm="horizontal" layout-align="center center">
            <md-button class="md-raised">Button</md-button>
            <md-button class="md-raised md-primary">Primary</md-button>
            <md-button disabled class="md-raised md-primary">Disabled</md-button>
            <md-button class="md-raised md-warn">Warn</md-button>
            <div class="label">raised</div>
        </section>

        <section layout="vertical" layout-sm="horizontal" layout-align="center center">
            <md-button class="md-fab" aria-label="Time">
                <md-icon icon="/img/icons/ic_access_time_24px.svg" style="width: 24px; height: 24px;"></md-icon>
            </md-button>

            <md-button class="md-fab" aria-label="New document">
                <md-icon icon="/img/icons/ic_insert_drive_file_24px.svg" style="width: 24px; height: 24px;"></md-icon>
            </md-button>

            <md-button class="md-fab" disabled arial-label="Comment">
                <md-icon icon="/img/icons/ic_comment_24px.svg" style="width: 24px; height: 24px;"></md-icon>
            </md-button>

            <md-button class="md-fab md-primary" md-theme="cyan" aria-label="Profile">
                <md-icon icon="/img/icons/ic_people_24px.svg" style="width: 24px; height: 24px;"></md-icon>
            </md-button>
            <div class="label">FAB</div>
        </section>

        <section layout="vertical" layout-sm="horizontal" layout-align="center center">
            <md-button class>Reset</md-button>
            <md-button class>RSVP</md-button>
            <div class="label">Button Group</div>
        </section>

        <section layout="vertical" layout-sm="horizontal" layout-align="center center">
            <md-button class="md-primary" md-theme="green">Button</md-button>
            <md-button class="md-primary md-raised" md-theme="indigo">Button</md-button>
            <md-button class="md-primary md-raised" md-theme="orange">Button</md-button>
            <md-button class="md-primary" md-theme="cyan">Button</md-button>
            <div class="label">Themed</div>
        </section>

    </md-content>
</div>

<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/angular-aria/angular-aria.js"></script>
<script src="../bower_components/angular-animate/angular-animate.js"></script>
<script src="../bower_components/hammerjs/hammer.js"></script>
<script src="../bower_components/angular-material/angular-material.js"></script>
<script>

    // Include app dependency on ngMaterial

    angular.module('YourApp', ['ngMaterial'])
        .controller("YourController", YourController);

    function YourController() {

    }

</script>

2 个答案:

答案 0 :(得分:10)

更新:Aaand可行!他们刚刚发布了v.0.5.0,现在包括主题。演示网站运行主人,这就是为什么它以前工作。 只需运行bower install angular-material,一切都很好。你仍然需要引用主题css。

<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-animate.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-route.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular-aria.min.js"></script>
<script src="bower_components/hammerjs/hammer.min.js"></script>
<script src="bower_components/angular-material/angular-material.js"></script>

<!-- default themes and core styles -->
<link rel="stylesheet" href="bower_components/angular-material/angular-material.css">

<!-- extra, overriding theme files -->
<link rel="stylesheet" href="bower_components/angular-material/themes/indigo-theme.css">
<link rel="stylesheet" href="bower_components/angular-material/themes/green-theme.css">

<!-- Your custom JavaScript code -->
<script>
angular.module('myApp', [ 'ngMaterial' ]);
</script>
</head>
<body>

<div ng-app="myApp" layout="vertical">

  <!-- The md-toolbar and all of its children will use the indigo theme -->
  <md-toolbar md-theme="indigo">
I'm indigo
  </md-toolbar>

  <!-- The md-content and all of its children will use the green theme -->
  <md-content md-theme="green">
and I'm green
  </md-content>

  <!-- The button uses default-theme, since no md-theme is found -->
  <md-button>Hello</md-button>

<md-progress-linear md-theme="green" mode="indeterminate" ng-value="30"></md-progress-linear>

</div>
</body>
</html>

答案 1 :(得分:3)

对于0.8.3,请参阅主题文档。

https://material.angularjs.org/#/Theming/01_introduction

您可以命名自己的主题&#39;在Google的主题文档中定义的以下之一:

  • 红色
  • 粉红色
  • 深紫色
  • 靛蓝
  • 蓝色
  • 浅蓝色
  • 青色
  • TEAL
  • 绿色
  • 浅绿色
  • 石灰
  • 黄色
  • 琥珀
  • 深橙
  • 褐色
  • 灰色
  • 蓝灰色

每个主题有4个意图:

  • 口音
  • 警告
  • 背景

要选择一个主题,你必须在JS中声明它:

 angular.module('myApp', ['ngMaterial'])
 .config(function($mdThemingProvider) {
   $mdThemingProvider.theme('default')
    .primaryPalette('pink')
    .accentPalette('orange');
 });