Miomir Dancevic Miomir Dancevic - 5 months ago 20
AngularJS Question

Angluar difference creating controller?

I am making some controller in Angular, when i created like this

aluPlanetApp.controller('KontaktController', function($scope) {
$scope.title= 'Kontakt';
$scope.id = '10';
$scope.users =[{"MIGX_id":"1","image":"upload/bridge.png"}];
});


It work ok, but when i try to make it like this, i got error

(function () {
'use strict';

aluPlanetApp.controller('KontaktController', KontaktController);

KontaktController.$inject = ['$scope'];

function KontaktController($scope) {
$scope.title= 'Kontakt';
$scope.id = '10';
$scope.users =[{"MIGX_id":"1","image":"upload/bridge.png"}];

activate();

function activate() { }
}
})();


This error

TypeError: aluPlanetApp.config(...) is not a function
aluPlanetApp.config(function($routeProvider) {


This is link to see entire JS

http://www.aluplanet.rs/app.js

Answer

Just get rid of aluPlanetApp variable completely and always use the getter version of angular.module()

angular.module('aluPlanetApp').controller(...
angular.module('aluPlanetApp').service(...
angular.module('aluPlanetApp').directive(...

See John Papa Angular Style Guide