I'm attempting to modularize my app... I'm already using requirejs, but I'm
trying to get the hang of the angular modules now...
I figured I'd start by placing my new admin section into a module. It's
just a simple controller with a template:
admin/
admin.module.js
admin.ctrl.js
admin.html
In admin.module.coffee, I register my controller, and insert the template
text into the $templateCache:
define(['angular', 'admin/admin.ctrl', 'text!admin/admin.html'], function
(angular, controller, template) {
app = angular.module('myapp.admin', []);
app.controller('adminController', controller);
app.run(['$templateCache', function ($templateCache) {
$templateCache.put('adminTemplate', template);
]);
return app;
});
This seemed like a nice clean way to go, but now I can't figure out how to
access my controller and template from the code in my main app:
I think I could access them in partials using ng-controller and ng-include,
but I want to add them as a route (using ui-router), rather than include
them into an existing page.
I tried injecting, but it doesn't seem to work:
app.js:
define(['angular', 'admin/admin.module'], function (angular) {
app = angular.module("myapp", ["myapp.admin"]);
app.config(['$stateProvider', 'adminController', 'adminTemplate',
function ($stateProvider, adminController, adminTemplate) {
$stateProvider.state( 'admin', {
url: "/admin",
controller: adminController,
template: adminTemplate
});
});
});
The error I'm getting is "Unknown provider: adminController"
So obviously, I'm doing it wrong...
I also tried injecting $templateCache, but got Unknown provider for that as
well. I've only ever seen app.config injecting "xxxProvider", to setting
up providers before later sections inject "xxx", so it seems that DI isn't
the right way to do this, but as far as I know, this is where you need to
set up the routes in $stateProvider
Is there a way to access the controller and template directly? I can
retrieve the module using angular.module('admin'), but that's as far as
I've got.
I'm confused, I must admit...I thought this would be straightforward...
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.