Angular does not work on server

I am trying to run my front-end AngularJS on a server. I use Yeoman to create an application. I download the most basic hello world application and I get plain HTML text with JavaScript loaded. The Chrome console says the following:

Error: Unknown provider: aProvider <- a
    at Error (<anonymous>)
    at http://../scripts/vendor/d10639ae.angular.js:2627:15
    at Object.getService [as get] (http://../scripts/vendor/d10639ae.angular.js:2755:39)
    at http://../scripts/vendor/d10639ae.angular.js:2632:45
    at getService (http://../scripts/vendor/d10639ae.angular.js:2755:39)
    at invoke (http://../scripts/vendor/d10639ae.angular.js:2773:13)
    at Object.instantiate (http://../scripts/vendor/d10639ae.angular.js:2805:23)
    at http://../scripts/vendor/d10639ae.angular.js:4620:24
    at update (http://../scripts/vendor/d10639ae.angular.js:13692:26)
    at http://../scripts/vendor/d10639ae.angular.js:8002:24 d10639ae.angular.js:5526

Does anyone experience the same thing and know a way out?

EDIT:

'use strict';

yoAngApp.controller('MainCtrl',['$scope', '$window', function($scope, $window) {
    $scope.awesomeThings = [
        'HTML5 Boilerplate',
        'AngularJS',
        'Testacular'
    ];

    $scope.records = [{ title : 'one' }, { title : 'two' }, { title : 'three' }, { title : 'four' }];

    $scope.greet = function() {
        ($window.mockWindow || $window).alert('Hello ' + $scope.name);
    }
}]
);
+5
source share
2 answers

As @ ŁukaszBachman suggested, you can use the $ inject annotation or use Inline Annotation if you want:

  • Keep dependency annotations close to your function definitions (for better readability).
  • Stay away from the polluting global namespace.

 

app.controller('UsersController',
  [
    '$scope', 'UserService', '$location', '$routeParams',
    function($scope, User, $location, $routeParams) {
      $scope.user = User.get({id: $routeParams.id});
      ...
    }
  ]
);
+4
source

, minifier , ?

Angular Js , minifier , . ? :

Minifier

function MyController($scope, $log) { ... }

DI. Angular $scope . $scope.

, , , :

function a(b, c) { ... }

, Angular , "a".

.

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

, ( ) $inject. Angular , $scope MyController. $log . , minifiers .

+8

All Articles