Skip to content

Instantly share code, notes, and snippets.

@adamkleingit
Created August 20, 2015 14:55
Show Gist options
  • Save adamkleingit/50e1af77771c8088859d to your computer and use it in GitHub Desktop.
Save adamkleingit/50e1af77771c8088859d to your computer and use it in GitHub Desktop.
Example of changing URL without refreshing the view
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();
}
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;
}
}
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