angularjs - How to declare and use modules, controllers, services and bootstrap manually in Angular? -


i'm trying build angularjs app has 1 controller, 1 service , bootstraps manually (no ng-app). problem keep having error :

argument 'appcontroller' not function, got string

html

<!doctype html> <html xmlns:ng="http://angularjs.org">     <head>         <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.0/angular.min.js" type="text/javascript"></script>         <script src="inc/bootstrap.js" type="text/javascript"></script>         <script src="inc/controllers.js" type="text/javascript"></script>         <script src="inc/services.js" type="text/javascript"></script>     </head>     <body ng-controller="appcontroller">         [...]     </body> </html> 

bootstrap.js

angular.element(document).ready(function() {     angular.bootstrap(document, ['htmlcontrollerapp']); }); 

controllers.js

angular.module('htmlcontrollerapp', []) .controller('appcontroller', 'connectionservice', ['$scope', function ($scope, connectionservice) {     // code }]); 

services.js

angular.module('htmlcontrollerapp') .factory('connectionservice', ['$rootscope', function ($rootscope) {     // code }]); 

thanks


edit - solution

in controllers.js, use instead :

angular.module('htmlcontrollerapp') .controller('appcontroller', ['$scope', 'connectionservice', function ($scope, connectionservice) {     // code }]); 

in bootstrap.js, "good practice" :

angular.module('htmlcontrollerapp', []); angular.element(document).ready(function() {     angular.bootstrap(document, ['htmlcontrollerapp']); }); 

this create module once in bootstrap.js , angularjs try retrieve in controllers.js , services.js.

this page you're looking for.

https://docs.angularjs.org/api/ng/function/angular.bootstrap

and change this

angular.module('htmlcontrollerapp', [])   .controller('appcontroller', 'connectionservice', ['$scope', function ($scope,     connectionservice) {     // code }]); 

to ->

angular.module('htmlcontrollerapp', [])   .controller('appcontroller', ['$scope', 'connectionservice', function ($scope, connectionservice) {     // code }]); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -