[英]How to use @angular/animations in angular asp.net core 2 template?
I can't import @angular/animations
in app.module.shared file:我无法在 app.module.shared 文件中导入
@angular/animations
: When i import
@angular/animations
in app.module.browser file animations don't work.当我在 app.module.browser 文件中导入
@angular/animations
,动画不起作用。
What i need to do for use material animations in angular asp.net core 2 template?在 angular asp.net core 2 模板中使用材质动画需要做什么?
I initially added the animations import into the app.module.shared file and I got the same error.我最初将动画导入添加到 app.module.shared 文件中,但出现了同样的错误。 To fix it I moved the import into the app.module.browser file.
为了修复它,我将导入移动到 app.module.browser 文件中。
This is how I left my module.browser:这就是我离开 module.browser 的方式:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppModuleShared } from './app.module.shared';
import { AppComponent } from './components/app/app.component';
@NgModule({
bootstrap: [ AppComponent ],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppModuleShared
],
providers: [
{ provide: 'BASE_URL', useFactory: getBaseUrl }
]
})
export class AppModule {
}
export function getBaseUrl() {
return document.getElementsByTagName('base')[0].href;
}
Example of using BrowserAnimationsModule: https://github.com/aspnet/JavaScriptServices/commit/c0c47e3def208873c470a524a826f8d235a5f9de使用 BrowserAnimationsModule 的示例: https : //github.com/aspnet/JavaScriptServices/commit/c0c47e3def208873c470a524a826f8d235a5f9de
The error you posted is caused because @angular/animations
uses DOM references, like document and window .你发布的错误是因为
@angular/animations
使用了 DOM 引用,比如document和window 。
By default, ASP.NET Core MVC SPA apps created using the initial template will pre-render your Javascript code on serverside, as defined in your Index view.默认情况下,使用初始模板创建的 ASP.NET Core MVC SPA 应用程序将在服务器端预渲染您的 Javascript 代码,如索引视图中所定义。
<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>
So you can't add DOM references on server and shared modules.所以你不能在服务器和共享模块上添加 DOM 引用。
You have to add @angular/animation to app.module.browser.ts
and then use it on your submodules and/or components.您必须将 @angular/animation 添加到
app.module.browser.ts
,然后在您的子模块和/或组件上使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.