Skip to main content
added 158 characters in body
Source Link
John Abraham
  • 18.9k
  • 37
  • 133
  • 242

Preface

Clicking a ui-sref links wont refresh named views' controller.

Question

How can I refresh the WeeklyCtrl When clicking on a ui-sref="root.store.page.ad({ adSlug: promo.code })" from SidePanelCtrl

note there is a reload on the page. I see the favicon blink but no re-init of any controllers routes.js

$stateProvider .state('root', { url: '/', abstract: true, views: { '': { templateUrl: 'views/main.html', controller: 'MainCtrl' } } }) .state('root.store', { url: ':storeSlug', views: { 'sidepanel': { templateUrl: 'views/partials/side-panel.html', controller: 'SidePanelCtrl' }, 'weekly': { templateUrl: 'views/partials/weekly.html', controller: 'WeeklyCtrl' }, } }) .state('root.store.page', { url: '/page', }) .state('root.store.page.ad', { url: '/:adSlug', }) 

index.html

<div ui-view=""></div> 

main.html

 <div ui-view="weekly"></div> <div ui-view="sidepanel"></div> 

side-panel.html

<a ng-repeat="promo in promos" ui-sref="root.store.page.ad({ adSlug: promo.code })" > <h3>...</h3> </a> 

When WeeklyCtrl init it triggers an api call to will trigger.

Pages.details.getPages($scope).success(function(data){ console.log(data); }); 

In the end I want this to trigger again when I switch between promos

UPDATE:

On click of a link: API responds 3 times. controller reinits multiple times 3 times

Preface

Clicking a ui-sref links wont refresh named views' controller.

Question

How can I refresh the WeeklyCtrl When clicking on a ui-sref="root.store.page.ad({ adSlug: promo.code })" from SidePanelCtrl

note there is a reload on the page. I see the favicon blink but no re-init of any controllers routes.js

$stateProvider .state('root', { url: '/', abstract: true, views: { '': { templateUrl: 'views/main.html', controller: 'MainCtrl' } } }) .state('root.store', { url: ':storeSlug', views: { 'sidepanel': { templateUrl: 'views/partials/side-panel.html', controller: 'SidePanelCtrl' }, 'weekly': { templateUrl: 'views/partials/weekly.html', controller: 'WeeklyCtrl' }, } }) .state('root.store.page', { url: '/page', }) .state('root.store.page.ad', { url: '/:adSlug', }) 

index.html

<div ui-view=""></div> 

main.html

 <div ui-view="weekly"></div> <div ui-view="sidepanel"></div> 

side-panel.html

<a ng-repeat="promo in promos" ui-sref="root.store.page.ad({ adSlug: promo.code })" > <h3>...</h3> </a> 

When WeeklyCtrl init it triggers an api call to will trigger.

Pages.details.getPages($scope).success(function(data){ console.log(data); }); 

In the end I want this to trigger again when I switch between promos

Preface

Clicking a ui-sref links wont refresh named views' controller.

Question

How can I refresh the WeeklyCtrl When clicking on a ui-sref="root.store.page.ad({ adSlug: promo.code })" from SidePanelCtrl

note there is a reload on the page. I see the favicon blink but no re-init of any controllers routes.js

$stateProvider .state('root', { url: '/', abstract: true, views: { '': { templateUrl: 'views/main.html', controller: 'MainCtrl' } } }) .state('root.store', { url: ':storeSlug', views: { 'sidepanel': { templateUrl: 'views/partials/side-panel.html', controller: 'SidePanelCtrl' }, 'weekly': { templateUrl: 'views/partials/weekly.html', controller: 'WeeklyCtrl' }, } }) .state('root.store.page', { url: '/page', }) .state('root.store.page.ad', { url: '/:adSlug', }) 

index.html

<div ui-view=""></div> 

main.html

 <div ui-view="weekly"></div> <div ui-view="sidepanel"></div> 

side-panel.html

<a ng-repeat="promo in promos" ui-sref="root.store.page.ad({ adSlug: promo.code })" > <h3>...</h3> </a> 

When WeeklyCtrl init it triggers an api call to will trigger.

Pages.details.getPages($scope).success(function(data){ console.log(data); }); 

In the end I want this to trigger again when I switch between promos

UPDATE:

On click of a link: API responds 3 times. controller reinits multiple times 3 times

Source Link
John Abraham
  • 18.9k
  • 37
  • 133
  • 242

Controller wont refresh when ui-sref state change

Preface

Clicking a ui-sref links wont refresh named views' controller.

Question

How can I refresh the WeeklyCtrl When clicking on a ui-sref="root.store.page.ad({ adSlug: promo.code })" from SidePanelCtrl

note there is a reload on the page. I see the favicon blink but no re-init of any controllers routes.js

$stateProvider .state('root', { url: '/', abstract: true, views: { '': { templateUrl: 'views/main.html', controller: 'MainCtrl' } } }) .state('root.store', { url: ':storeSlug', views: { 'sidepanel': { templateUrl: 'views/partials/side-panel.html', controller: 'SidePanelCtrl' }, 'weekly': { templateUrl: 'views/partials/weekly.html', controller: 'WeeklyCtrl' }, } }) .state('root.store.page', { url: '/page', }) .state('root.store.page.ad', { url: '/:adSlug', }) 

index.html

<div ui-view=""></div> 

main.html

 <div ui-view="weekly"></div> <div ui-view="sidepanel"></div> 

side-panel.html

<a ng-repeat="promo in promos" ui-sref="root.store.page.ad({ adSlug: promo.code })" > <h3>...</h3> </a> 

When WeeklyCtrl init it triggers an api call to will trigger.

Pages.details.getPages($scope).success(function(data){ console.log(data); }); 

In the end I want this to trigger again when I switch between promos