在浏览器上启动 Angular 应用程序时遇到问题。一切都可以用代码说话,但我仍然收到此错误:
发现了合成属性
。请包括其中之一@routerAnimations
或BrowserAnimationsModule
在您的 申请。NoopAnimationsModule
我已经查过关于这个主题的帖子,有很多,但他们的答案都一样:
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
并将其包含在应用程序模块的导入中。
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"
}
}
<div [@routerAnimations]="myOutlet.state">
<router-outlet #myOutlet></router-outlet>
</div>
添加线条
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
和
imports: [
BrowserAnimationsModule,
...
]
到
app.module.ts
实际上解决了它
有一点是您肯定需要在活动模块中添加
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)')),
]),
],
如有疑问请在评论中回复
除非您导入 BrowserAnimationsModule,否则 Sidenav 将无法工作。因此,从“@angular/platform-browser/animations”导入它。
就我而言,我使用的是 Angular 17 模式:独立。要解决该问题,请根据链接使用 main.ts 文件中的流动脚本:https://angular.io/guide/animations
bootstrapApplication(AppComponent, {
providers: [
provideAnimations(),
]
});
希望这个脚本对某人有帮助。
我解决了这个问题,问题是我的 app.component.html 中的“@routerAnimations”:
<div [@routerAnimations]="myOutlet.state">
<router-outlet #myOutlet></router-outlet>
</div>
当我删除它时,一切正常