Skip to content

Commit

Permalink
fix(uiSref): Ensure URL once param checks pass
Browse files Browse the repository at this point in the history
Fixes #2091
  • Loading branch information
nateabele committed Aug 19, 2015
1 parent 9dd9aef commit 9dc31c5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 2 additions & 5 deletions src/stateDirectives.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,18 @@ function $StateRefDirective($state, $timeout) {
require: ['?^uiSrefActive', '?^uiSrefActiveEq'],
link: function(scope, element, attrs, uiSrefActive) {
var ref = parseStateRef(attrs.uiSref, $state.current.name);
var def = { state: ref.state, href: null, nav: true, params: null };
var def = { state: ref.state, href: null, params: null };
var type = getTypeInfo(element);
var active = uiSrefActive[1] || uiSrefActive[0];

def.options = extend(defaultOpts(element, $state), attrs.uiSrefOpts ? scope.$eval(attrs.uiSrefOpts) : {});

var update = function(val) {
if (val) def.params = angular.copy(val);
if (!def.nav) return;

def.href = $state.href(ref.state, def.params, def.options);
def.nav = (def.href !== null);

if (active) active.$$addStateInfo(ref.state, def.params);
if (def.nav) attrs.$set(type.attr, def.href);
if (def.href !== null) attrs.$set(type.attr, def.href);
};

if (ref.paramExpr) {
Expand Down
8 changes: 4 additions & 4 deletions test/stateDirectivesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('uiStateRef', function() {
url: '/contacts',
template: '<a ui-sref=".item({ id: 5 })" class="item">Person</a> <ui-view></ui-view>'
}).state('contacts.item', {
url: '/:id',
url: '/{id:int}',
template: '<a ui-sref=".detail" class="item-detail">Detail</a> | <a ui-sref="^" class="item-parent">Parent</a> | <ui-view></ui-view>'
}).state('contacts.item.detail', {
template: '<div class="title">Detail</div> | <a ui-sref="^" class="item-parent2">Item</a>'
Expand Down Expand Up @@ -130,7 +130,7 @@ describe('uiStateRef', function() {
$q.flush();

expect($state.current.name).toEqual('contacts.item.detail');
expect($stateParams).toEqual({ id: "5" });
expect($stateParams).toEqual({ id: 5 });
}));

it('should transition when given a click that contains no data (fake-click)', inject(function($state, $stateParams, $q) {
Expand All @@ -147,7 +147,7 @@ describe('uiStateRef', function() {
$q.flush();

expect($state.current.name).toEqual('contacts.item.detail');
expect($stateParams).toEqual({ id: "5" });
expect($stateParams).toEqual({ id: 5 });
}));

it('should not transition states when ctrl-clicked', inject(function($state, $stateParams, $q) {
Expand Down Expand Up @@ -393,7 +393,7 @@ describe('uiStateRef', function() {
$q.flush();

expect($state.$current.name).toBe("contacts.item.detail");
expect($state.params).toEqual({ id: "5" });
expect($state.params).toEqual({ id: 5 });
}));

it('should resolve states from parent uiView', inject(function ($state, $stateParams, $q, $timeout) {
Expand Down

0 comments on commit 9dc31c5

Please sign in to comment.