Skip to content

Instantly share code, notes, and snippets.

@IlanFrumer
Created January 6, 2014 11:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save IlanFrumer/8281567 to your computer and use it in GitHub Desktop.
Save IlanFrumer/8281567 to your computer and use it in GitHub Desktop.
Angular.js ui-router directive to Reload current state with different params
app.directive("uiSrefParams", function($state) {
return {
link: function(scope, elm, attrs) {
var params;
params = scope.$eval(attrs.uiSrefParams);
return elm.bind("click", function(e) {
var button;
if (!angular.equals($state.params, params)) {
button = e.which || e.button;
if ((button === 0 || button === 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
scope.$evalAsync(function() {
return $state.go(".", params);
});
return e.preventDefault();
}
}
});
}
};
});
@IlanFrumer
Copy link
Author

Example

Change language:
<a ui-sref-params="{lang: 'en'}">english</a>
<a ui-sref-params="{lang: 'ru'}">russian</a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment