angularjs - Module is not available, multiple controllers -
i spent 2 days , didn't find error:
error: $controller:ctrlreg controller name not registered. controller name 'clientcontroller' not registered.
i have 2 controllers , app.js:
js/app.js js/controllers/client-controller.js js/controllers/login-client-controller.js
clientcontroller:
angular.module('loginclientmodule',[]) .controller('clientcontroller', ['$scope', '$http', '$state', function($scope, $http, $state) {....//some code }])
logincontroller:
angular.module('loginclientmodule',[]) .controller('loginclientcontroller', ['$scope', '$http', '$state', function($scope, $http, $state) {....//some code }])
the app.js:
const app = angular.module('clientproviderapp', [ 'ui.router', 'loginclientmodule' ]) app.config(['$stateprovider', '$urlrouterprovider', function($stateprovider, $urlrouterprovider) { $urlrouterprovider.otherwise('/clients') $stateprovider .state('about', { url : '/about', template : '<h2>about stuff</h2>' }) .state('loginclient', { url:'/loginclient', templateurl:'views/login.html', controller: 'loginclientcontroller' }) .state('clients', { url: '/clients', templateurl: 'views/clients.html', controller: 'clientcontroller' }) }])
index html:
<!doctype html> <html> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0-rc.2/angular.min.js"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.min.js"> </script> <script type="text/javascript" src="js/app.js"></script> <script type="text/javascript" src="js/controllers/client-controller.js"></script> <script type="text/javascript" src="js/controllers/login-client-controller.js"></script> </head> <body ng-app="clientproviderapp"> <div ui-view></div> </body> </html>
what doing wrong? tried several methods stackoverflow , didn't me. thank in advance!
the key problem here angular.module('mymodulename', [])
creates new module. doing in both client-controller.js
, login-client-controller.js
.
instead, should make sure first, create module once using angular.module('loginclientmodule',[])
, in second file, use angular.module('loginclientmodule')
get existing module.
Comments
Post a Comment