Created
August 20, 2015 14:55
-
-
Save adamkleingit/50e1af77771c8088859d to your computer and use it in GitHub Desktop.
Example of changing URL without refreshing the view
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function DashboardCtrl(DashboardFilter, pubsub) { | |
var self = this; | |
function init() { | |
// Bindable filter, updates automatically | |
self.filter = DashboardFilter.getFilter(); | |
// Listen to filter change: | |
pubsub.on(DASHBOARD_FILTER_CHANGE, function(oldFilter, newFilter) { | |
// Example handling of filter change: | |
if (oldFilter.dashboardName != newFilter.dashboardName) { | |
self.initPanes(); | |
} | |
}); | |
} | |
self.initPanes = function() { | |
$http.get('panes', DashboardFilter.dashboardName) | |
.then(...) | |
} | |
self.onChangeEndDate = function() { | |
$state.go('.', {end: self.filter.endDate}); | |
} | |
init(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function DashboardFilterState() { | |
this.setFilter = function(filterParams) { | |
var oldFilter = angular.copy(this.filter); | |
// Set the new filter: | |
// parse filterParams and copy to current filter | |
angular.copy(this.parseFilter(stateParams), this.filter); | |
// Notify about the change: | |
if (oldFilter != newFilter) { | |
pubsub.transmit(DASHBOARD_FILTER_CHANGE, oldFilter, newFilter); | |
} | |
} | |
this.getFilter = function() { | |
return this.filter; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
state('dashboard', { | |
url: '/dashboard', | |
template: 'dashboard.html', | |
controller: 'DashboardCtrl', | |
}) | |
.state('dashboard.filtered', { | |
url: '?search&start&end&name', | |
onEnter: function(DashboardFilter, $stateParams, pubsub) { | |
// Set the new filter: | |
var newFilter = DashboardFilter.setFilter($stateParams); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment