1

In my HTML page, there are three tabs each having unique controller bonded to it as following:

MainHTML (app.pages.managing.html):

<div id="DetailsViewContainer">
    <div ng-if="selectedTab === 'tab1'">
        <div ng-include="getTabUrl('tab1')" ng-controller="DetailsController"></div>
    </div>
</div>
<div id="CoursesViewContainer">
    <div ng-if="selectedTab === 'tab2'">
        <div ng-include="getTabUrl('tab2')" ng-controller="CoursesController"></div>
    </div>
</div>
<div id="UsersViewContainer">
    <div ng-if="selectedTab === 'tab3'">
        <div ng-include="getTabUrl('tab3')" ng-controller="UsersController"></div>
    </div>
</div>

The main html is already bonded with parent controller as follows:

'use strict';
 angular.module('app.pages.manage').config([
    '$routeProvider',
     function($routeProvider, appSettingsProvider) {
         $routeProvider
         .when('/:lang?/group/landing/v2/manage/',
              {
                   templateUrl: '/js/app/pages/manage/views/app.pages.managing.html',
                   controller: 'mainController'
              });
         }
 ]);

My requirement is that on click event, I want to initialize the bonded controller corresponding to selected tab. For three bonded controller in HTML file I don't have separate url config so I can't use $location service. I explored $state in UI router as I don't want to initialize the parent controller which might be helpful (after defining three different routes for three controllers). But I am using ng-route module so it's not an option for me.

So is there any ways I can make my controller reload programmatically while switching tab (without url)? I am also thinking to bind this controller through routing rather than ng-controller, but then also I want to prevent reloading the state of parent controller (mainController) and then reload only selected controller which I can't find a solution with ng-route.

1
  • For above problem I also tried to use ui-router as my problem needs parent-child relation for views. But for some reason it's dependency collide with other modules in my project and it throws error. On prototype ui-router works great. I noticed there is a way for invoking controller function programmatically but there doesn't seem to be any way for invoking whole controller on click event. Any help would be appreciated. Thanks. Commented May 5, 2017 at 2:31

2 Answers 2

1

This might be helpful. This is a tutorial to dynamically load controller in the angularJS

https://weblogs.asp.net/dwahlin/dynamically-loading-controllers-and-views-with-angularjs-and-requirejs

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

Comments

0

Nehal, you should really consider just investing some time to work with UI router. What you want can be handled elegantly using nested/child states in UI router, it was made for this kind of stuff.

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.