angular-route-segment:查找routeSegmentProvider的当前位置

时间:2014-09-04 18:47:33

标签: angularjs angular-route-segment

我正在尝试在构建路线时找到routeSegmentProvider的当前位置,因为其中一个未正确设置。有什么方法可以让我在树上的当前位置?

这基本上就是我要做的......

   var routeProvider = routeSegmentProvider;
   $.each(parentNodes, function(index, parentNode) {
       routeProvider.within(parentNode.Segment);
   });

   //here is where I would like to check to see where I am at in the tree before I apply this
   routeProvider.within(node.Segment).segment(subNode.Segment, {
       default: subNode.Default == true,
       template: subNode.Template == undefined ? "" : subNode.Template,
       templateUrl: subNode.TemplateUrl == undefined ? "" : subNode.TemplateUrl,
       controller: node.Controller == undefined ? "" : node.Controller
   });

   routeProvider.root();

2 个答案:

答案 0 :(得分:0)

我最终还是让这个工作起来了。这是我的解决方案:

        var currentLocation = null;
        $.each(parentNodes, function(index, parentNode) {
            currentLocation = routeSegmentProvider.within(parentNode.Segment);
        });

        if (currentLocation != null) {
            currentLocation.within(node.Segment).segment(subNode.Segment, {
                default: subNode.Default == true,
                template: subNode.Template == undefined ? "" : subNode.Template,
                templateUrl: subNode.TemplateUrl == undefined ? "" : subNode.TemplateUrl,
                controller: node.Controller == undefined ? "" : node.Controller
            });
        } else {
            routeSegmentProvider.within(node.Segment).segment(subNode.Segment, {
                default: subNode.Default == true,
                template: subNode.Template == undefined ? "" : subNode.Template,
                templateUrl: subNode.TemplateUrl == undefined ? "" : subNode.TemplateUrl,
                controller: node.Controller == undefined ? "" : node.Controller
            });
        }

        routeSegmentProvider.root();

答案 1 :(得分:0)

<span ng-bind="$routeSegment.name"/> 

使用routeSegment时,上面的代码段是查找当前路径的更简单方法。