Comments (3)
Actually, if you look at the index.js file that's in a module folder, that is where the controller for the module is defined. The controller defined in the Directive is simply specifying the controller used for that Directive (which happens to be the same as the module controller).
That said, resolves can be a bit tricky sometimes, and they can act strangely with this architecture since resolves don't like controllers that are used outside of the stateProvider call. However, I use resolves in my own app that uses this architecture and it works perfectly fine.
Here's an example:
function userRoutes($stateProvider) {
var user = {
name: 'user',
abstract: true,
url: '/user',
template: '<div ui-view></div>',
controller: 'UsersCtrl'
},
userID = {
name: 'user.id',
abstract: true,
url: '/:id',
template: '<div ui-view></div>',
controller: 'UsersCtrl',
resolve: {
user: function(Restangular, $stateParams) {
return Restangular.one('users', $stateParams.id).get();
}
}
};
$stateProvider.state(user);
$stateProvider.state(userID);
}
userRoutes.$inject = ['$stateProvider'];
module.exports = userRoutes;
In this case, this is the top level config file for the users module. The main module doesn't contain a Directive or any HTML. That's all handled within the sub-modules. Any sub module controller within the users module can be injected with the "user" object defined in the userID resolve and then all you have to do is write $scope.user = user;
in your sub-module controllers and you should be good to go.
Let me know if you run into a problem and I'll see what I can do to help you resolve it. Cheers!
from angular-gulp-browserify-starter.
hmm... so I modeled something pretty similar to what you have there, but I'm running into an issue on the module controller side. let's just use your example there, in your UsersCtrl controller. Would you be adding something like...
function UsersViewCtrl(user) {
// BLAH BLAH BLAH
}
...
UsersViewCtrl.$inject = ['user'];
If I do this and alert out the value of the resolved variable, I see the result I'm looking for, but my template doesn't render and I get an error (that I'd expect) that it can't find the provider userProvider...
update... as I was writing this, I came across the issue. In my directive for the module, I was setting the controller. Because it was calling a controller in a controller, it was screwing with the $inject and i was getting the "can't find provider" error message. I took out the controller from the directive and everything works fine now. Thanks a ton for your help!
edit...
to illustrate more, here's the part I deleted from the skeleton to make it work in my app. This was found in the app / modules / home / homeDirective.js
controller: 'HomeViewCtrl', // called from homeController.js
from angular-gulp-browserify-starter.
Yeah, sorry, I could have been clearer. When you're using controllers as part of a resolve, the controller you specify can't be connected to the DOM (either via HTML or through a directive). That's why I used the resolve on a top level abstract route using a controller meant specifically for sub-module inheritance. I find that with this application structure, it's generally best to use your resolves at the top module level (as opposed to the sub-module levels) and then inject the resolved object into your sub-module controllers.
Anyway, glad you got it sorted out!
from angular-gulp-browserify-starter.
Related Issues (20)
- Prefix options are passed to pipe rather than prefix. HOT 1
- nested views/modules HOT 9
- Prerender.io HOT 2
- License HOT 4
- Adding karma-coverage HOT 25
- using injection of bower components inside modules HOT 1
- Unresolved Dependencies HOT 1
- Filters HOT 1
- adding vendor chart.js angular-chart.js HOT 6
- Dublicate bundle for libs in vendorJs task HOT 3
- Triying to colaborate: push a new branch HOT 1
- Troubles adding ngTable to angular-gulp-browserify-starter HOT 2
- $stateParams undefined HOT 10
- MongoDB HOT 2
- When javascript syntax Error occur the gulp will not show the error and not start the app HOT 1
- Collapse menu do not work
- How to inject services etc. into controllers HOT 3
- images HOT 5
- Native Services HOT 4
- Problem setting up crawlme HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular-gulp-browserify-starter.