Reputation: 2472
For whatever reason I cannot automatically resolve anything in the constructor of services, components, ect. I have other projects that don't have this problem.
For example a component with the following constructor:
constructor(
private location: Location
) {
results in the following error: Can't resolve all parameters for SearchQueryComponent: (?).
As a workaround I've been doing the following:
constructor(
@Inject(forwardRef(() => Location)) private location: Location
) {
What am I missing? Every other project I've worked on in angular does not require the decorators to resolve injectables.
My tsproject.json
does have experimentalDecorators
and emitDecoratorMetadata
set to true.
polyfills.ts:
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
Upvotes: 0
Views: 72
Reputation: 2472
after reviewing the example provided by @jb-nizet. Found that the import './polyfills';
was not imported first in the main.ts
file.
Changed main.ts
from:
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import './polyfills';
to
import './polyfills';
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
Everything works!
Upvotes: 1