ngParty / ng-metadata

Angular 2 decorators and utils for Angular 1.x
https://hotell.gitbooks.io/ng-metadata/content/
MIT License
355 stars 46 forks source link

Uncaught Error: [$injector:modulerr] Failed to instantiate module appModule#5 due to: Error: [$injector:unpr] Unknown provider: ... #212

Closed AlexCppns closed 7 years ago

AlexCppns commented 7 years ago

Hello,

I have been trying to adapt a small module using ng-metadata and I am stuck with some DI problem:

angular.js:118 Uncaught Error: [$injector:modulerr] Failed to instantiate module appModule#5 due to: Error: [$injector:unpr] Unknown provider: FeatureProvider

The provider I am trying to inject:

import { Feature } from './Feature';
import { FeatureService } from './FeatureService';
import { IFeatureProvider } from './IFeatureProvider';
import { Injectable } from 'ng-metadata/core';

@Injectable()
export class FeatureProvider implements IFeatureProvider, ng.IServiceProvider {
    supportedFeatures: Feature[];
    overriddenFeatures: Feature[];

    /**
     * Application features supported
     * @param features
     */
    setSupportedFeatures(features: Feature[]): void {
        this.supportedFeatures = features;
    }

    setOverriddenFeatures(features: Feature[]): void {
        this.overriddenFeatures = features;
    }

    constructor() {

    }

    $get(): FeatureService {
        return new FeatureService(
            this.supportedFeatures,
            this.overriddenFeatures
        );
    }
}

The place where I am injecting it:

import * as angular from 'angular';
import { FeatureProvider } from './FeatureProvider';
import { FeatureToggle } from './feature-toggle/feature-toggle.directive';
import { NgModule } from 'ng-metadata/core';

console.log(FeatureProvider);
@NgModule({
    declarations: [FeatureToggle],
    providers: [ FeatureProvider]
})
export class FeatureFlag {}