简体   繁体   English

如何在 angular asp.net core 2 模板中使用@angular/animations?

[英]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 引用,比如documentwindow

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.

相关问题 Asp.net核心2采用角度6模板 - Asp.net core 2 with angular 6 template ASP.NET Core 2 Angular模板中的Angular CLI? - Angular CLI in ASP.NET Core 2 Angular template? Asp.net核心2.0 Angular模板:添加身份和身份验证 - Asp.net core 2.0 Angular template: add identity and authentication 在Kestrel服务器上运行ASP.NET Core Angular模板? - Running ASP.NET Core Angular template on Kestrel server? 同一项目中的ASP.NET核心模板包和角度1应用程序 - ASP.NET Core Template Pack and angular 1 app in same project 有没有办法将我的 Angular ASP.net 核心模板转换为 ASP.net 核心 MVC - Is there a way to convert my Angular ASP.net Core template to ASP.net core MVC 如何向asp.net角度模板添加角度材料 - How to add angular material to asp.net angular template 在带有 angular 5 模板的 asp.net core 2.0 中找不到 Angular Material 核心主题 - Could not find Angular Material core theme in asp.net core 2.0 with angular 5 template 如何使用 Angular i18n 和 ASP.NET Core 6.0 进行开发和生产? - How can i use Angular i18n with ASP.NET Core 6.0 for development and production? 如何逐步使用 Blazor WASM 作为现有 Asp.Net Core Angular 项目的一部分 - How to use Blazor WASM gradually as part of existing Asp.Net Core Angular project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM