2

I am trying to use resolve in AngularJS ngRoute. But I get this error

On browser console I get the below error,

Error: [$injector:unpr] Unknown provider: formTypeProvider <- formType <- addController

var myApp  = angular.module('myApp', ['ngRoute']);

myApp.config(function($routeProvider) {

    $routeProvider.when('/add', {
        templateUrl : 'partials/add.html',
        controller : "addController",
        resolve : {
            formType : function() {
                return 'CREATE';
            }
        }
    }).when('/view/:id', {
        templateUrl : 'partials/view.html',
        controller : 'addController',
        resolve : {
            formType : function() {
                return 'VIEW';
            }
        }
    });
})



// Add
myApp.controller('addController', ['$scope', '$http', '$location', 'formType', function($scope, $http, $location, formType) {

    console.log("formType : " +formType);
    //  
}   

Update:-

Plunker : http://embed.plnkr.co/cLHnFGwt5it7T2itipG9/preview

2
  • do you also have ng-controller assigning same controller in html? Code shown should work fine Commented Nov 9, 2015 at 18:23
  • @charlietfl Thanks I added a Plunker, the browser console log still has that error. Commented Nov 10, 2015 at 11:34

1 Answer 1

4

You should not use the ng-controller in the HTML again. Remove ng-controller from HTML, then the problem will be solved.

See this pluker : http://embed.plnkr.co/0DI6Ogq640qn0Pp6YO8z/preview

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Should I never use ng-app & ng-conroller in index.html ?
Since you already defined the controller with the routes, you should not add it again in the html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.