Reputation: 10624
For now, I need to import the underscore library in each component.
But I want to import that only once in my root component which is AppComponent.
If I import underscore only in AppComponent, and use in sub-components, I go an error
ReferenceError: _ is not defined
import * as _ from 'underscore';
@Component({
...
})
export class AppComponent { }
How can I make it works?
Upvotes: 0
Views: 95
Reputation: 1059
Importing the things you are going to use within a component is the way it has to be done.
Think about the way you declare an injectable service. You declare the service in a module then that becomes injectable within that area of the app, however you still have to import the service class into the component.
If possible set up a generic service just for underscore, and pass your values into it. However you will still need to declare that service on each page you use it.
Upvotes: 2