1

I can't import @angular/animations in app.module.shared file: enter image description here When i import @angular/animations in app.module.browser file animations don't work.

What i need to do for use material animations in angular asp.net core 2 template?

6
  • You have to import from @angular/platform-browser/animations for BrowserAnimationsModule or NoopAmimationsModule for no animations. Commented Sep 26, 2017 at 8:42
  • @Edric I imported the BrowserAnimationsModule module into the files app.module.browser and app.module.shared. When i import a module in the file app.module.shared, an error occurs. When i import a module in the file app.module.browser, the animations do not work. Commented Sep 26, 2017 at 8:49
  • What's your full error stacktrace? Post it somewhere. Commented Sep 26, 2017 at 8:55
  • @Edric dropmefiles.com/P4sFz html file with full error Commented Sep 26, 2017 at 9:00
  • Sorry, but I still can't troubleshoot your issue without actual code. Commented Sep 27, 2017 at 13:18

2 Answers 2

1

I initially added the animations import into the app.module.shared file and I got the same error. To fix it I moved the import into the app.module.browser file.

This is how I left my 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

Sign up to request clarification or add additional context in comments.

Comments

0

The error you posted is caused because@angular/animations uses DOM references, like document and 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.

<app asp-prerender-module="ClientApp/dist/main-server">Loading...</app>

So you can't add DOM references on server and shared modules.

You have to add @angular/animation to app.module.browser.ts and then use it on your submodules and/or components.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.