0

I'm working on a angular project with angular-ui-route and the use of nested views like:

 $stateProvider.state('app', {
     url: '/form',
     views: {
         'p1@modals': {
             templateUrl: 'form1.html'
         }
         'p2@modals': {
             templateUrl: 'form2.html',
             controller: function($scope) {
                 //do some thing
             }
         }
     }
 })

however, we have several sub views of /form, each of them has a controller, we don't want to put all the controller code in a js file so we write the config as:

 $stateProvider.state('app', {
     url: '/form',
     views: {
         'p1@modals': {
             templateUrl: 'form1.html'
         }
         'p2@modals': {
             templateUrl: 'form2.html',
             controller: 'P2Controller.js'
         }
     }
 })

in P2Controller.js we define the controller as:

 define(['app'], function(app) {
    app.controller('P2Controller', function($scope) {

    });
 })

the problem is how can load the P2Controller.js and invoke the controller

1
  • Before you'll get your answer, observe this and that Commented Nov 6, 2015 at 9:29

1 Answer 1

0

Why not to use standart technique:

config-file:

angular.module('yourModule', [])
.config(function($stateProvider) {
    $stateProvider.state('app', {
        url: '/form',
        views: {
            'p1@modals': {
                templateUrl: 'form1.html'
            },
            'p2@modals': {
                templateUrl: 'form2.html',
                controller: 'P2Controller'
            }
        }
    })
})

P2Controller.js:

angular.module('yourModule')
.controller('P2Controller', function() {
    //your stuff
});

P.S. 'p1@modals' means that modals is parent for view 'p1'. Be careful with this logic

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.