ui-view doesn't work when used inside angularj

2019-08-10 01:44发布

问题:

I want to wrap some ui-view elements inside a custom angularjs directive

<wrapper>
    <ul>
      <li><a ui-sref="route1">Route 1</a></li>
      <li><a ui-sref="route2">Route 2</a></li>
    </ul>

    <div class="well" ui-view="viewA"></div>        
    <div class="well" ui-view="viewB"></div>        
</wrapper>

The custom directive does nothing but transcluding the content:

myapp.directive('wrapper', function($compile){
    return {
        restrict: 'E',
        replace: true,
        transclude:true,
        template: '<div class="godWrapper" ng-transclude></div>'
    };
});

See the demo in Plunker

It seems that ui-view doesn't like to be wrapped as when I remove the wrapper element the demo works with no problem. Is this a bug in ui-router or am I doing something wrong?

UPDATE:

Apparently this is a known issue. Issue 774 and Issue 886

回答1:

Sorry to answer my own question, but after some diving through angular-ui-router known issues and source code, I found that the problem is with the latest release of angular-ui-router (0.2.8) as discussed in here. The following demo is utilising the 0.2.7 release without the mentioned problem. Perhaps this will be useful for someone else

http://plnkr.co/edit/u2LE7gFUGSpAmUNK3fhP?p=preview