Skip to content

Loading…

route directive fails to create scope #434

Closed
tisztamo opened this Issue · 14 comments

5 participants

@tisztamo

It seems to me that the uiRoute directive doesn't create a new scope so if I use it on multiple tags the last $uiRoute wins.

This is not working:

<li data-ui-route="/public" ng-class="{active: $uiRoute}"><a href="#">Public</a></li>
<li data-ui-route="/private" ng-class="{active: $uiRoute}"><a href="#">Private</a></li>

But this is OK:

<li ng-repeat="btn in navbuttons" ui-route="{{btn.route}}" ng-class="{active: $uiRoute}"><a href="#">{{btn.label}}</a></li>

(The demo on the site uses ng-repeat which creates a new scope for every iterated tag so it is working correctly.)

@sudhakar

I had the same problem too. After setting scope: true on the uiRoute solves the problem as new scope is created for it.

@ProLoser
AngularUI member

Man I never thought about that. Thanks for the tip, will change immediately.

@ProLoser
AngularUI member

Crap, how the fuck do you test child scopes.

@ProLoser
AngularUI member

If anyone wants to help fix the tests with scope:true it would help me out a lot

@ajoslin

Did you try something like this?

var elm = $compile('<my-directive></my-directive>');
var childScope = elm.children().scope();
@ProLoser
AngularUI member

Is that the proper way to do it? I mean the element itself has the scope. Or maybe I should just do elm.scope(). I just sort of figured doing scope() was a hackish way to go about things.

@ProLoser
AngularUI member

Also, the dom element doesn't have children.

@ProLoser ProLoser pushed a commit that referenced this issue
Dean Sofer fix(route): Fixed #434 - Added scope:true
Tests are failing though
3dbb2ee
@leeola

@sudhakar re:

I had the same problem too. After setting scope: true on the uiRoute solves the problem as new scope is created for it.

How exactly would you do that?

I'm not familiar with Angular/AngularUI's method for providing options to modules, but when i tried to emulate the ui-select2 example shown on the homepage, i couldn't seem to set scope: true.

I tried

myModule.value('ui.config', {
  uiRoute: {
    scope: true
  }
});

with the names uiRoute, route, and 'ui-route' to no avail. Any advice?

@sudhakar

Nope. For the time being, I have modified the uiRoute directive itself with scope: true, so that it creates a new scope for the element & will be available for its child DOM as well. As of now, it works for me, but I havent tested it in other scenarios.

@leeola

Okay, thanks for replying!

@ProLoser
AngularUI member

@leeolayvar it's a bug with the directive that I forgot to address, and I can't merge the fix in until I have the tests passing :frowning:

@ProLoser ProLoser closed this
@leeola

@ProLoser Any idea when this fix will be published to bower? I'm not sure if it's intended for 0.5.0 or not. Either way, it's not shipped with 0.4.0

@ProLoser
AngularUI member

@leeolayvar this repo is no longer being actively developed. The latest version (which I believe includes the fix) can be found at angular-ui/ui-utils

@leeola

Yea, i was using Route from ui-utils (it does indeed include the fix).

Sounds good though! My apologies for not knowing this repo is closed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.