1

使用弹性布局 2.0.0-rc.1

扫描堆栈我找不到任何关于此的内容。(rc.1 很新)

我正在关注@Angular/flex-layout 的此文档,并希望使用响应式功能部分。我想在各种媒体查询断点处为元素提供条件类。

下面是我的代码的简化示例。

<div class="box" [ngClass]=" {'remove-margin-top': false}"
                 [ngClass.sm]=" {'remove-margin-top': true}">

    <div class="child"></div>
</div>

当上面的代码只包含[ngClass]=" {'remove-margin-top': false}"一切时,一切都很好。没有模板解析错误。

[ngClass.sm]=" {'remove-margin-top': true}"在模板解析生成时添加它时出现问题......

模板解析错误:无法绑定到“ngClass.sm”,因为它不是“div”的已知属性

我已经能够确认 FlexLayoutModule 已正确导入到模块中,并且其他 flex-layout 特定指令工作正常。

主要模块导入

import { FlexLayoutModule } from '@angular/flex-layout';
import { CommonModule } from '@angular/common';
...

@NgModule({
imports: [
  CommonModule,
  MomentModule,
  FlexLayoutModule
],

Package.json 的一部分

"dependencies": {
"@angular/common": "4.0.0-rc.1",
"@angular/compiler": "4.0.0-rc.1",
"@angular/core": "4.0.0-rc.1",
"@angular/forms": "4.0.0-rc.1",
"@angular/http": "4.0.0-rc.1",
"@angular/material": "2.0.0-beta.2",
"@angular/flex-layout": "2.0.0-rc.1",
"@angular/platform-browser": "4.0.0-rc.1",
"@angular/platform-browser-dynamic": "4.0.0-rc.1",
"@angular/router": "4.0.0-rc.1",
"angular2-moment": "1.1.0",
...
}
"devDependencies": {
"@angular/cli": "1.0.0-rc.0",
"@angular/compiler-cli": "4.0.0-rc.1",
"@types/core-js": "0.9.35",
"@types/hammerjs": "2.0.34",
"@types/jasmine": "2.5.35",
"@types/node": "6.0.60",
"@types/socket.io-client": "1.4.27",
"@types/source-map": "0.1.27",
"@types/stompjs": "2.3.0",
"@types/webpack": "1.12.34",
"@types/webrtc": "0.0.21",
...
}     
4

0 回答 0