How to define controllers in multiple files - AngularJs

前端 未结 4 1263
深忆病人
深忆病人 2021-02-03 23:37

I am trying to define controllers in separate files, but I\'m getting the error:

transactionsController not a function got undefined

4条回答
  •  天命终不由人
    2021-02-03 23:54

    You can do this stuff by creating modules. Create module and respective controllers. And inject that module to the main app module.

    Transactions.js
    
    (function() {
       'use strict';
       angular.module('tmodule', []);
    })();
    
    (function() {
       'use strict';
        angular.module('tmodule').controller('transactionsController', ['$scope', '$http', 
                function ($scope, $http){
        }]);
    
    })();
    

    Now inject the "tmodule" to your Common.js file-

      var app = angular.module("spModule", ["ngMessages", "ui.bootstrap","tmodule"]);
    

提交回复
热议问题