Search code examples
angularjsliferayportlet

Service Injection Error on Liferay Portlet


I have develop a Liferay portlet and using AngularJS for the slient side. By using service injection such as $scope in controller will produce an error of the following:-

Error: Unknown provider: aProvider <- a

Example code:-

<script>
function PayrollCalcCtrl($scope){
}
</script>

If $scope is removed, no error will occur. Any workaround to avoid this situation.


Solution

  • Your JS optimizer/obfuscator is messing with your dependencies. Take a look at the DI docs.

    You'll want to define your controller in $inject or inline annotation:

    var MyController = function(myScope) {
      ...
    }
    MyController.$inject = ['$scope'];
    

    or

    app.controller('MyCtrl', ['$scope', function($scope) {
      ...;
    }]);