1

In my HTML I have three columns where I am rendering 3 different HTML templates.

 <div id="col1" ui-view="col1"></div>
 <div id="col2" ui-view="col2"></div>
 <div id="col3" ui-view="col3"></div>

State demo which will render all this is like following.

$stateProvider
  .state('demo',{
    views: {
      'col1': {
        templateUrl: 'FirstTemplate.html'
      },
      'col2': {
        templateUrl: 'SecondTemplate.html'
      },
      'col3': {
        templateUrl: 'ThirdTemplate.html'
      }
    }
  })

My question is, how can I change templateurl of col3 from ThirdTemplate.html to NewTemplate.html, without changing the state.

Aditya Ponkshe
  • 3,840
  • 4
  • 39
  • 58

2 Answers2

1

To answer this:

My question is, how can I change templateurl of col3 from ThirdTemplate.html to NewTemplate.html, without changing the state. ?

It is not possible. It is not intended nor supported.

The idea behind the UI-Router is navigation among states (even without using url, $state.go()). Once the state TO is found/resolved, all its setting are converted into implementations (controllerProvider returning controller or string which is used to find controller, templateProvider returning template, etc.)

After that, state is stable and solid. We can use some other angular features (directives) to manipulate the DOM, but unless we will change the state - its parts are fixed.

In case, we can accept state change (including current state reload) we can profit e.g. from Template Provider:

NOTE: state change above means: 1) navigate to other or 2) reload current.

Community
  • 1
  • 1
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
0
<div ng-include="'NewTemplate.html'"></div>

<div ng-hide="'NewTemplate.html'">Thirdtemplate.html</div>
Naresh Kumar
  • 276
  • 2
  • 10
  • 2
    Hi @Naresh, thanks for your answer, but could you please add a few words of explanation? A code-only answer isn't always self explanatory :) – Lea Cohen Jan 20 '15 at 06:48
  • In Thirdtemplate.html page include a new html(NewTemplate.html) using ng-include directive based on conditions you can hide the view of previous html i.e in templateUrl (Thirdtemplate.html) – Naresh Kumar Jan 20 '15 at 07:28
  • @Nersh - great, almost there ;) Just edit your answer to add to it what you wrote in the comment! – Lea Cohen Jan 20 '15 at 11:40