0

I am working with blade template engine. I want to follow a convention of "One Controller per Page" to easily handle code. I have one JS file which has few controllers which will be used in all files/pages So i included in my template file which will automatically generated in each page. Code is as follows

angular.module('MyApp',['angularFileUpload'])
.factory('MyFactory', ['$http',function($http) {
    return{
      get: function(callback){
          $http.get('my-url')
          .success(function(data) {
              callback(data);
            });
      }
    };
}])
.controller('GlobalController',['$scope','$http','MyFactory',function($scope,$http,MyFactory){
    SchoolFactory.get(function(data){
       console.log(data);
    });
    // Few Function which will be called in all pages
}]);

Now When create a new page using that template that includes above JS, I get error. Here is what I create new js file.

angular.module('MyApp',[])
.controller('SomeController',['$scope','$http',function($scope,$http){
    // Few Function which will be called in all pages
}]);

Any Page which include this module i get error in console that SomeController is not a function.

Please help me. Thanks in advance.

2 Answers 2

4

This is same problem which i faced when i started working with Angular JS. Your code has very little error.

You can create multiple angular.module in single page but only one can have dependencies.

angular.module('MyApp',['angularFileUpload'])

angular.module('MyApp') 

From your second module remove empty array [].

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

Comments

3
angular.module('MyApp')
.controller('SomeController',['$scope','$http',function($scope,$http){
    // Few Function which will be called in all pages
}]);

Remove the , [] in the module. Any time you pass an array to the module function, it recreates the module. Since you want to add something to an existing module, leave it off.

Comments

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.