angularjs - angular inject module into multiple modules -
i'm loading module on base html page called userfromserver
. i'd inject both main app module , mixpanel module. i'm getting injection error if try inject userfromserver
analytics.mixpanel
(angular mixpanel). circular dependency error or missing something? should userfromserver
available modules? how can inject userfromserver
both modules?
var app = angular.module('app', ['userfromserver', 'analytics.mixpanel']) // main app currentuser injectable var mixp = angular.module('analytics.mixpanel', ['userfromserver']) mixp.config(['$mixpanelprovider', 'currentuser', function($mixpanelprovider, currentuser) { // use currentuser here }]);
userfromserver module
<body ng-app="app" ng-cloak> <base href="/"> <div class="container"> <div ng-view=""></div> </div> <script type="text/javascript"> angular.module('userfromserver', []) .service('currentuser', function() { <% if logged_in %> this.name = '<%= @user.name %>'; this.first_name = '<%= @user.first_name %>'; this.id = '<%= @user.id %>'; this.uuid = '<%= @user.profile.uuid %>'; <% end %> }) </script> </body>
the stack trace is:
failed instantiate module app due to: failed instantiate module analytics.mixpanel due to: unknown provider: currentuser
this happens because currentuser
service instance injected config
block. service providers can injected here.
since currentuser
constant object doesn't depend on other services , should available during config phase, may constant
service:
angular.module('userfromserver', []) .constant('currentuser', { <% if logged_in %> name: '<%= @user.name %>', first_name: '<%= @user.first_name %>', id: '<%= @user.id %>', uuid: '<%= @user.profile.uuid %>' <% end %> })
Comments
Post a Comment