简体   繁体   English

NullInjectorError:Angular 6中没有AnimationBuilder的提供者

[英]NullInjectorError: No provider for AnimationBuilder in Angular 6

Hello I working with the Angular 6 And also with the material design 您好我使用Angular 6以及材料设计

I have included all the dependency of the material and also of the animations as well 我已经包含了材料的所有依赖性以及动画的依赖性

It's not giving error at time of the compilation but I get following error at time of browser rendering 它在编译时没有给出错误,但是在浏览器渲染时我得到了跟随错误 在此输入图像描述

I have imported all required dependencies 我已导入所有必需的依赖项

import { animate, AnimationBuilder, AnimationPlayer, style } from '@angular/animations';

AppComponent.html:40 ERROR Error: taticInjectorError(AppBrowserModule)[FuseSidebarComponent -> AnimationBuilder]: 
 StaticInjectorError(Platform: core)[FuseSidebarComponent -> AnimationBuilder]: 
NullInjectorError: No provider for AnimationBuilder!
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get (core.js:1034)
at resolveToken (core.js:1271)
at tryResolveToken (core.js:1216)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
at resolveToken (core.js:1271)
at tryResolveToken (core.js:1216)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get (core.js:1113)
at resolveNgModuleDep (core.js:8161)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:8849)
at resolveDep (core.js:9214)



import { animate, AnimationBuilder, AnimationPlayer, style } from '@angular/animations';
import { DOCUMENT } from '@angular/common';
@Injectable({
providedIn: 'root'
})
export class SampleClass
{
player: AnimationPlayer;

constructor(
    private _animationBuilder: AnimationBuilder,
    @Inject(DOCUMENT) private _document: any,
)
{
    this._init();
}

private _init(): void
{

    this.testScreen = this._document.body.querySelector('#test-screen');


    if ( this.testScreen )
    {
        this.player =
        this._animationBuilder
            .build([
                style({
                    opacity: '0',
                    zIndex : '99999'
                }),
                animate('400ms ease', style({opacity: '1'}))
            ]).create(this.testScreen);

        setTimeout(() => {
            this.player.play();
        }, 0);
    }
} 
}

EDIT : 编辑:

BROWSER_ANIMATIONS_PROVIDERS is provided within BrowserAnimationsModule , so you should be importing BrowserAnimationsModule in your module. BROWSER_ANIMATIONS_PROVIDERS是内提供BrowserAnimationsModule ,所以你应该导入BrowserAnimationsModule您的模块中。 This allows you to use AnimationBuilder in your component. 这允许您在组件中使用AnimationBuilder

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

@NgModule({
  imports: [
    BrowserAnimationsModule
  ]
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM