NullInjectorError: No provider for ViewportScroller

前端 未结 3 1926
陌清茗
陌清茗 2021-01-07 19:15

I\'m building a simple angular application, using Angular Material to desing the front-end. The app just have 2 components rendered in the same page. When I serve the app, t

3条回答
  •  臣服心动
    2021-01-07 20:04

    I had the same error - updating Angular in a project workes for me (it is a new project with only Angular Material, few simple components and simple routing).

    ng update @angular/cli @angular/core
    

    https://update.angular.io/#7.2:8.0

    The error ocurred after I did:

    npm install -S @angular/material @angular/cdk @angular/animations
    npm uninstall @angular/core
    npm install -S @angular/core
    

    as a solution for error "export 'ɵɵinject' was not found in '@angular/core' (thrown after adding Angular Material to a brand new project).

    It worked until I added routing and got NullInjectorError: No provider for ViewportScroller. But as mentioned in the beginning - updating the whole project to Angular v8 seems the solution.

提交回复
热议问题