Reputation: 27303
When I'm reading the blog about dynamic component creation, I have seen the below inject decorator inside the constructor
.
constructor(@Inject(ComponentFactoryResolver) factoryResolver) {
this.factoryResolver = factoryResolver
}
Why we are injecting like this? Can any one please explain.
Upvotes: 0
Views: 174
Reputation: 1162
It means that angular will handle automatically and internally the instance creation for the factoryResolver.
In latest versions of angular you don't need to specify the @Inject in the constructor, nor the assign to this.factoryResolver:
constructor (private factoryResover: ComponentFactoryResolver) {}
You can read more about angular dependency injection here: https://angular.io/guide/dependency-injection
Upvotes: 1