为什么Material Design布局不适用于Angular 4?

问题描述 投票:2回答:1

我按照入门guide安装了Material Design,但是当我尝试复制Layout Containers API Reference page底部的“Responsive Layouts”示例时,我注意到了一些问题:

enter image description here

布局属性显然在我的实现中不起作用(屏幕分辨率为1446x150):

enter image description here

当我在index.html中指定它时,显然没有使用Roboto字体。

我希望我错过了一些明显的东西,因为认为这样一个简单的例子不可复制是非常令人失望的。

的index.html

  <!doctype html>
  <html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Personas</title>
    <base href="/">

    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">

    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">
  </head>
  <body>
    <app-root></app-root>
  </body>
  </html>

styles.css的

@import '~@angular/material/prebuilt-themes/indigo-pink.css';

app.component.html

<div layout="row" layout-xs="column">
  <div flex>
    I'm above on mobile, and to the left on larger devices.
  </div>
  <div flex>
    I'm below on mobile, and to the right on larger devices.
  </div>
</div>

Angular CLI: 1.5.0
Node: 9.2.0
OS: darwin x64
Angular: 5.1.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

@angular/cdk: 5.0.2
@angular/cli: 1.5.0
@angular/material: 5.0.2
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.42
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.0
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.4.2
webpack: 3.8.1
angular material-design angular-material
1个回答
3
投票

你在角度(2+)上使用了角度材质1语法,尽管它只与angularjs(1)兼容。我认为那些不兼容。

尝试安装material 2

Flex没有完全集成到材料2中,它有own separate github

但是现在你可以通过using grid listnpm install @angular/flex-layout@latest --save实现你在这里展示的东西,但是语法可能与角度材料1不同。

如果您更喜欢前一种方法,那么这是一个取自角材料2的例子

在comp.html中

<mat-grid-list cols="4" rowHeight="100px">
  <mat-grid-tile
    *ngFor="let tile of tiles"
    [colspan]="tile.cols"
    [rowspan]="tile.rows"
    [style.background]="tile.color">
    {{tile.text}}
  </mat-grid-tile>
</mat-grid-list>

在comp.ts

  tiles = [
    {text: 'One', cols: 3, rows: 1, color: 'lightblue'},
    {text: 'Two', cols: 1, rows: 2, color: 'lightgreen'},
    {text: 'Three', cols: 1, rows: 1, color: 'lightpink'},
    {text: 'Four', cols: 2, rows: 1, color: '#DDBDF1'},
  ];

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.