angularjs - Unable to load provider -


i trying use angular provider can dynamically load sub-modules within $routeprovider of angular application. however, getting 1 of 2 errors:

error: [$injector:modulerr] failed instantiate module mainapp due to: [$injector:unpr] unknown provider: myrouteprovider

error: [$injector:nomod] module 'mainapp' not available! either misspelled module name or forgot load it. if registering module ensure specify dependencies second argument.

here's have:

main.js

require.config({     baseurl : '',     version : '1.0', });  require([     'app',     'my-route-mod/my-route-mod.module',     'my-route-mod/my-route-mod.provider',     'main-app/main-app.config',     'main-app/main-app.run',     /* other initial modules */ ],function(){    angular.bootstrap(document,['mainapp']); }); 

app.js

(function(){     'use strict';     /* global angular, $ */      angular.module('mainapp',[         'myroutemod', /* module not want load */         'ngroute',         'ngcookies'     ]); })(); 

my-route-mod/my-route-mod.module.js

(function(){     'use strict';     /* global angular */      angular.module('myroutemod',[]); })(); 

my-route-mod/my-route-mod.provider.js

(function(){     'use strict';     /* global angular */      angular.module('myroutemod')     .provider('myroutemodprovider',provider);      provider.$inject = [];      function provider() {         var provider = this;         provider.$get = function () {             return { route : somefunction };         }          function somefunction(){...}     } })(); 

main-app/main-app.config.js

(function(){     /* global angular */     'use strict';     angular.module('mainapp').config(config);      config.$inject = [         'myroutemodprovider',         '$routeprovider',         '$locationprovider',         '$controllerprovider',         '$compileprovider',         '$filterprovider',         '$provide'     ];      function config(         myroutemodprovider,         $routeprovider,         $locationprovider,         $controllerprovider,         $compileprovider,         $filterprovider,         $provide     ) {          /* ... config stuff ... */     } })(); 

index.html

<!doctype> <html>     <head><title>my app</title></head>     <body>         <!-- other stuff -->         <div ng-view></div>         <!-- other stuff -->          <script src="vendor-stuff"></script>         <script src="vendor/require.js" data-main="main">/script>     </body> </html> 

i took requirejs out of equation , getting same issue provider not loading.

i either mainapp not available, or myroutemod not available, or myroutemodprovider not available.

suggestions please.

angular naming conventions. providers, string 'provider' gets added constructor name. so, if have:

angular.module('mymod').provider('mickeymouse',provider); 

then angular 'mickeymouseprovider'. so, if do

angular.module('mymod').provider('mickeymouseprovider',provider); 

then angular 'mickeymouseproviderprovider'

hope saves bit of time.


Comments

Popular posts from this blog

xcode - CocoaPod Storyboard error: -

c# - AutoMapper - What's difference between Condition and PreCondition -