Skip to content

Commit c12bf9a

Browse files
author
Rory Fitzpatrick
committed
feat(uiSref): add target attribute behaviour
Change the behaviour of ui-sref to match angular $location service, ignoring any click event on an anchor with a 'target' attribute set.
1 parent c985f25 commit c12bf9a

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/stateDirectives.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ function $StateRefDirective($state, $timeout) {
8787

8888
element.bind("click", function(e) {
8989
var button = e.which || e.button;
90-
91-
if ((button === 0 || button == 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey) {
90+
if ((button === 0 || button == 1) && !e.ctrlKey && !e.metaKey && !e.shiftKey && !element.attr('target')) {
9291
// HACK: This is to allow ng-clicks to be processed before the transition is initiated:
9392
$timeout(function() {
9493
scope.$apply(function() {

test/stateDirectivesSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,17 @@ describe('uiStateRef', function() {
149149
expect($state.current.name).toEqual('');
150150
expect($stateParams).toEqual({ id: "5" });
151151
}));
152+
153+
it('should not transition states when element has target specified', inject(function($state, $stateParams, $document, $q, $timeout) {
154+
el.attr('target', '_blank');
155+
expect($state.$current.name).toEqual('');
156+
157+
triggerClick(el);
158+
$q.flush();
159+
160+
expect($state.current.name).toEqual('');
161+
expect($stateParams).toEqual({ id: "5" });
162+
}));
152163
});
153164

154165
describe('forms', function() {

0 commit comments

Comments
 (0)