Created
January 6, 2014 11:34
-
-
Save IlanFrumer/8281567 to your computer and use it in GitHub Desktop.
Angular.js ui-router directive to Reload current state with different params
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
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(); | |
} | |
} | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example