“Uncaught Error: [$injector:unpr]” with angular after deployment

后端 未结 7 1200
灰色年华
灰色年华 2020-11-30 21:45

I have a fairly simple Angular application that runs just fine on my dev machine, but is failing with this error message (in the browser console) after I deploy it:

7条回答
  •  攒了一身酷
    2020-11-30 22:18

    Ran into the same problem myself, but my controller definitions looked a little different than above. For controllers defined like this:

    function MyController($scope, $http) {
        // ...
    }
    

    Just add a line after the declaration indicating which objects to inject when the controller is instantiated:

    function MyController($scope, $http) {
        // ...
    }
    MyController.$inject = ['$scope', '$http'];
    

    This makes it minification-safe.

提交回复
热议问题