Within my main dashboard
parent state, I have two child states: tags
and tickers
.
When a button in the tickers
state is clicked, only the tags
state should refresh. Currently, both states are refreshing.
https://i.sstatic.net/tP6mK.png
https://i.sstatic.net/QiJBq.png
The onInit tickersController
console.log should only be executed once. However, the tagsController should run every time a ticker is clicked.
var routerApp = angular.module('routerApp', ['ui.router']);
routerApp.config(function($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/dash');
var dash = {
name: 'dash',
url: '/dash?ticker',
params: {
ticker: 'AAA'
},
views: {
'': { templateUrl: 'dashboard.html' },
'tagsList@dash': {
url: '/tags',
templateUrl: 'tags-list.html',
controller: 'tagsController'
},
'tickersList@dash': {
url: '/tickers',
templateUrl: 'tickers-list.html',
controller: 'tickersController'
},
'alertsList@dash': {
url: '/alerts',
templateUrl: 'alerts-list.html',
controller: 'alertsController'
}
}
};
$stateProvider
.state(dash);
});
routerApp.controller('tagsController', function($scope, $state) {
$scope.ticker = $state.params.ticker;
function getList(ticker) {
switch(ticker) {
case 'AAA' : return ['aaa tag 1', 'aaa tag 2', 'aaa tag 3'];
case 'BBB' : return ['bbb tag 1', 'bbb tag 2', 'bbb tag 3'];
case 'CCC' : return ['ccc tag 1', 'ccc tag 2', 'ccc tag 3'];
}
}
$scope.tags = getList($state.params.ticker);
this.$onInit = function() {
console.log('onInit tagsController');
};
});
routerApp.controller('tickersController', function($scope, $state) {
$scope.changeScotchState = function(theTicker) {
$state.go('dash', { ticker: theTicker });
};
$scope.tickers = [
'AAA', 'BBB', 'CCC'
];
this.$onInit = function() {
console.log('onInit tickersController', $state.params.ticker);
};
});
routerApp.controller('alertsController', function($scope, $state) {
this.$onInit = function() {
console.log('onInit alertsController', $state.params.ticker);
};
});