Reputation: 141
When I use Flex in my new Angular 8 app, I face this Error message.
ERROR
Error: StaticInjectorError(AppModule)[DefaultLayoutDirective -> StyleUtils]: StaticInjectorError(Platform: core)[DefaultLayoutDirective -> StyleUtils]: NullInjectorError: No provider for StyleUtils!
Package.json:
{
"name": "angular",
"version": "0.0.0",
"private": true,
"dependencies": {
"@angular/cdk": "^9.0.0-rc.8",
"@angular/common": "8.0.0",
"@angular/compiler": "8.0.0",
"@angular/core": "8.0.0",
"@angular/flex-layout": "^9.0.0-beta.28",
"@angular/forms": "8.0.0",
"@angular/platform-browser": "8.0.0",
"@angular/platform-browser-dynamic": "8.0.0",
"@angular/router": "8.0.0",
"core-js": "2.6.9",
"rxjs": "6.5.2",
"tslib": "^1.9.0",
"zone.js": "0.9.1"
},
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.10.0",
"@angular/cli": "~7.0.2",
"@angular/compiler-cli": "~7.0.0",
"@angular/language-service": "~7.0.0",
"@types/node": "~8.9.4",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.1.1"
}
}
Upvotes: 3
Views: 3995
Reputation: 1
You will need to have your @angular/flex version under the same version or similar to your @angular/cli version. You can check them both in package.json.
"dependencies":
{
"@angular/flex-layout": "^8.0.0-beta.27",
.....
"devDependencies":
{
"@angular/cli": "~8.0.6",
To upgrade or downgrade you @angular/version, you just remove the curent version line in the package.json and run this command to install the one that you want
npm i @angular/flex-layout@the_version_you_want
ex: npm i @angular/[email protected]
And that should resolve your problem...
Upvotes: 0
Reputation:
I had this problem and could only solve it by adding the providers to the module
import { ɵMatchMedia, BreakPointRegistry, PrintHook } from '@angular/flex-layout/core';
import { FlexLayoutModule, StyleUtils, StylesheetMap, LayoutStyleBuilder, MediaMarshaller, LayoutAlignStyleBuilder, FlexStyleBuilder } from '@angular/flex-layout';
providers:[
PrintHook,
StyleUtils,
StyleSheet,
StylesheetMap,
LayoutAlignStyleBuilder,
LayoutStyleBuilder,
FlexStyleBuilder,
MediaMarshaller,
ɵMatchMedia,
BreakPointRegistry],
Upvotes: 1
Reputation: 101
I tried the above solution but didn't work. I did the following which worked for me
ng update --next @angular/cli --force
npm install typescript@latest
Upvotes: 0
Reputation: 5181
Change this line of dependency in your package.json:
"@angular/flex-layout": "8.0.0",
and import this module into your app.module.ts
:
@NgModule({
declarations: [
AppComponent
],
exports: [
AppComponent
],
imports: [
...
FlexLayoutModule
],
})
The most recent iteration of the package could be buggy, therefore I would recommend to use an older stable version instead of the beta version. It should also reflect the version number of the other @angular packages to ensure compatibility.
Upvotes: 2