Service instance is not available for child component in angular2

后端 未结 2 1769
栀梦
栀梦 2020-12-11 20:14

I have created some services which should be shared within whole application but for some reason child components are throwing error Error: DI Exception at NoProviderE

2条回答
  •  伪装坚强ぢ
    2020-12-11 20:39

    SystemJs is case sensitive (by design). If you use different path name in your project files like this:

    main.ts

    import { categoryService } from './categoryService';
    

    category-component.ts

    import { categoryService } from './categoryservice';
    

    then System js will make double imports

    This way angular2 will find other instance of service object in providers Map keys.

    Despite the fact that key exists in Map object.

    has method of Map will return false. That's why you're receiving an error.

    See also more information about key equality within Map object at this page https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map#Key_equality

提交回复
热议问题