Wednesday, 8 March 2017

Unknown Provider : $locationProviderProvider <- $locationProvider

Error :

Unknown Provider : $locationProviderProvider <- $locationProvider <- myCtrl 

also got this error.

You're allowed to inject a $location into a controller, but not a $locationProvider.

Instead, the $locationProvider can be injected into a config method:


Solution :
var app = angular.module("myApp", []);

app.config(function($locationProvider) {
  $locationProvider.html5Mode(true);
});

app.controller("myCtrl", function($location) {
  $location.path("/some/path");
});


And since I made this additional mistake: it's not just that you should add an app.config bit, but also remember to remove $locationProvider from the controller arguments, or you'll keep getting this error.


Also you have to add <base> tag in your html file <head> tag



 <base href="/myDemoProject/">

No comments:

Post a Comment

Spring boot with CORS

CORS (Cross-Origin Resource Sharing) errors occur when a web application running in a browser requests a resource from a different domain or...