如何在Angular2中实现材质精简步进器

时间:2017-02-20 13:00:35

标签: angular material-design-lite

更新:基本上没有应用任何材料样式。我试过切换和滑块,但它不起作用。

我有一个用CLI创建的angular2项目,我正在使用material lite进行样式化。

在我的项目中添加和使用 mdl-stepper 的正确方法是什么?

我按照此处的说明(https://github.com/ahlechandre/mdl-stepper)但我的步进器组件无法加载,如演示中所示。

我的app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { MaterialModule } from '@angular/material';
import { MDL } from './MaterialDesignLiteUpgradeElement';
import 'hammerjs';


import { HomeComponent } from './components/home/home.component'

import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    MDL
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    MaterialModule.forRoot(),

  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

在我的styles.css中,我有:

@import '~material-design-lite/dist/material.blue-deep_orange.min.css';
@import '~mdl-stepper/stepper.css';
@import 'https://fonts.googleapis.com/icon?family=Material+Icons' 

在我的angular-cli.json中,我有:

"scripts": [
        "../node_modules/material-design-lite/material.min.js",
        "../node_modules/mdl-stepper/stepper.min.js"
      ],

HTML如下所示:

<ul class="mdl-stepper mdl-stepper--horizontal" id="demo-stepper-nonlinear">
    <li class="mdl-step">
        <span class="mdl-step__label">
            <span class="mdl-step__title">
                <span class="mdl-step__title-text">Core goal</span>
                <span class="mdl-step__title-message">Summarize if needed</span>
            </span>
        </span>
        <div class="mdl-step__content">
            <h2>sample 1</h2>
        </div>
        <div class="mdl-step__actions">
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored mdl-button--raised" data-stepper-next>
                Continue
            </button>
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect" data-stepper-cancel>
                Cancel
            </button>
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect" data-stepper-back disabled>
                Back
            </button>
        </div>
    </li>
    <li class="mdl-step">
        <span class="mdl-step__label">
            <span class="mdl-step__title">
                <span class="mdl-step__title-text">Images</span>
                <span class="mdl-step__title-message">Summarize if needed</span>
            </span>
        </span>
        <div class="mdl-step__content">
            <h2>Sample 2</h2>
        </div>
        <div class="mdl-step__actions">
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored mdl-button--raised" data-stepper-next>
                Continue
            </button>
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect" data-stepper-cancel>
                Cancel
            </button>
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect" data-stepper-back>
                Back
            </button>
        </div>
    </li>
    <li class="mdl-step">
        <span class="mdl-step__label">
            <span class="mdl-step__title">
                <span class="mdl-step__title-text">Sub goals</span>
                <span class="mdl-step__title-message">Summarize if needed</span>
            </span>
        </span>
        <div class="mdl-step__content">
            <h2>Sample 3</h2>
        </div>
        <div class="mdl-step__actions">
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--colored mdl-button--raised" data-stepper-next>
                Continue
            </button>
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect" data-stepper-cancel>
                Cancel
            </button>
            <button class="mdl-button mdl-js-button mdl-js-ripple-effect" data-stepper-back>
                Back
            </button>
        </div>
    </li>
</ul>

更新 :如果我从styles.css中删除stepper.css,那么结果如下所示: enter image description here

使用stepper.css :(按钮和内容消失)

enter image description here

1 个答案:

答案 0 :(得分:0)

我的整个<ul>元素位于具有*ngIf约束的div中。扼杀,当我删除那个约束时,我的步进开始看起来正确。我不知道为什么。