Beside the routing issue, suppose I've a view and on route change I need to 
change some part of the view, so It'll be hard define that through template 
url in routes. So please suggest how to do that. I don't want to use same 
html written in two different files for two separate routes.

On Monday, July 28, 2014 2:40:32 PM UTC+5:30, Indranil Mondal wrote:
>
> Hi, I'm newbie in Angular JS. I'm trying to structure my application with 
> Angular JS & Require JS. After studying multiple blogs and documents I've 
> structured my application like the following. 
>
>
>
> <https://lh6.googleusercontent.com/-TokRSvq6shw/U9X8H8fRM_I/AAAAAAAAAGA/UAqUERNOeUk/s1600/File.png>
>
>
> I'm following angular-requirejs-seed 
> <https://github.com/tnajdek/angular-requirejs-seed> for my application. 
> But I'm confused about few things, whether those are the best practices or 
> I can improve my code. So I need suggestions from the experts.
>
>
> 1. *Defining controller for the modules*:- In my application there is a 
> main module, which is defined within app.js and there are two more modules, 
> one is User module and the second one is Admin module. I'm added both User 
> & Admin module as the dependency of main module. Now for user module I need 
> to define few controllers, which will be defined in separate files. So in 
> main.js of UserModule I've written:-
>
> define(['angular'], function (angular) {
>
> return angular.module('UserModule', [])
>
> .controller(LoginCtrl', ['$scope', '$injector', function($scope, 
> $injector) {
>
> require(['controllers/logincontrollerl'], function(loginctrl) {
>
> $injector.invoke(loginctrl, this, {
>
> '$scope': $scope
>
> });
>
> });
>
> }]);
>
> });
>
>
> And then within logincontroller.js I've written
>
>
> define([], function() {
>
> return ['$scope', function($scope) {
>
> $scope.$apply();
>
> }];
>
> });
>
>
> As we can't define a controller until a module is defined, so we can't add 
> the controller as the top most require part of main.js. But is it good to 
> define all the controllers within main.js and require all those in this 
> way? What I want is, to define each controller within the controller file 
> itself not within the main.js. So please suggest me what should I do.
>
>
> 2. *Defining routers*:- In the router.js I've written:-
>
>
> define(['app'], function (app) { 
>
> return app.config(['$routeProvider', function($routeProvider) {
>
> $routeProvider.when('/signin', {
>
> templateUrl: 'app/modules/user/views/signin.html'
>
> });
>
> $routeProvider.otherwise({
>
> redirectTo: '/home'
>
> });
>
> }]);
>
> });
>
>
> Here for a specific route I need to define the template url, but I don't 
> think it's good. Because not only I've to define the template url for each 
> route but also I need to define the controller name for each route. So 
> either I've to write :-
>
>
> $routeProvider.when('/signin', {
>
> templateUrl: 'app/modules/user/views/signin.html',
>
> controller: 'LoginCtrl'
>
> });
>
>
> or if I just declare the template url, then within sign.html I've to 
> declare the ng-controller directive. But router will decide which template 
> show when we have modules and controllers?
>
>
> What I want is, on each route the router will fire an event or something 
> like that to the corresponding module, say UserModule and the module will 
> redirect it to a specific controller and the controller will decide which 
> template to show. I think that may be better structure. So please suggest 
> me what should I do to create this type of structure.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>   
>
> <https://lh6.googleusercontent.com/-TokRSvq6shw/U9X8H8fRM_I/AAAAAAAAAGA/UAqUERNOeUk/s1600/File.png>
>

-- 
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.

Reply via email to