Error: $injector: unpr Unknown Provider

In previous article we discussed about form update ,for this we used services, most of the developers getting common errors while injecting the service in controllers. Now we will discuss
a common error as shown below.
Error: $injector:unpr Unknown Provider
To resolve this we need to check three things let’s check those three now.

Need to define the service and check spelling, before we inject into controller
Here we will check code which makes unknown provider error.

In the above code we defined the forumFactory service in editRegistration controller which will cause injector error due to service which is not defined in the app.js file. To fix this error we need to create the service which we defined in editRegistration controller as below.

Creating multiple angular modules in same app. js file, will cause the error.
If we define two angular modules in same app.js which leads to error, code looks like below

In the above code we defined welcome module two times it will causes , Error: $injector: unpr Unknown Provider. To fix these error we need to define single angular module as below.

READ  How to retrieve data from mysql and display in codeigniter view?

Trying to inject one controller into another controller, will cause the error.
Now let’s check the code which causes the error.

We should not inject controller into another controller,scope object into anything ,that’s not a controller or a directive .For example a service will cause , Error: $injector: unpr Unknown Provider. It will consider as service mistakenly let’s check the below code which causes error.

Thanks for reading this article, for any queries please use comment system, subscribe for eknowledgetree for new and fresh articles.

Leave a Reply