Angular 4 - 请在您的应用程序

时间:2017-10-11 08:08:30

标签: angular

我在浏览器上启动Angular应用程序时出现问题。一切都是代码说话,但我仍然收到这个错误:

  

找到合成属性@routerAnimations。请包括   您的“BrowserAnimationsModule”或“NoopAnimationsModule”   应用

我已经检查了这个主题的帖子,并且有很多,但所有人都回答了同样的问题:

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

并将其包含在app模块的导入中。

imports: [
    BrowserAnimationsModule,
    ... 
]

这就是我所做的但仍然有同样的错误。我一直在寻找这个解决方案的好几个小时。谁知道什么可以解决它?感谢

这是我的package.json:

{
  "name": "angular-bc",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "core-js": "^2.4.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.4.3",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}

3 个答案:

答案 0 :(得分:1)

有一点绝对是您需要在活动模块中添加BrowsersAnimationModule。但是除此之外,您需要为该合成选择器(此处为animations)提及@routerAnimations,它是Angular Component Meta

@Component({
  selector: 'app-card-grid',
  templateUrl: './card-grid.component.html',
  styleUrls: ['./card-grid.component.scss'],
  animations: [
    trigger('routerAnimations', [
      state('collapsed', style({ height: '0px', minHeight: '0' })),
      state('expanded', style({ height: '*' })),
      transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
    ]),
  ],

如果仍有疑问,请回复评论

答案 1 :(得分:0)

import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

imports: [
    BrowserAnimationsModule,
    ... 
]

实际上可以解决

答案 2 :(得分:-5)

我解决了这个问题,问题是app.component.html中的“@routerAnimations”:

<div [@routerAnimations]="myOutlet.state">
    <router-outlet #myOutlet></router-outlet>
</div>

当我删除它时,一切正常