2016-08-02 68 views
0

我想根据某些路径在我的AngularJS应用中隐藏一个头元素。到目前为止,我有这样的:

<header logo="appModel.config.logoUrl" ng-hide="currentPath==='/brandHealth/metricsWidget'"></header> 

这工作得很好,但是当我改变currentPath'/brandHealth/*'这是行不通的。我需要它为brandHealth子集中的所有网址工作。任何方式来做到这一点?

谢谢进阶

+0

我有'currentPath'的方式vailable通过我的控制器是这样的:'$ scope.currentPath = $ location.path();' – amigo21

+0

你使用什么路由器?如果您使用的是UI路由器,则可以使用它轻松完成。 – apaul

+0

@apaul使用ngroute – amigo21

回答

1

更改条件:

'/brandHealth/metricsWidget'.split('/')[0] === currentPath 

但是,你应该做的控制器上

$scope.containsPath = '/brandHealth/metricsWidget'.split('/')[0] === currentPath 

然后在你的头元素

<header logo="appModel.config.logoUrl" ng-hide="containsPath"></header> 
+0

谢谢!太棒了 – amigo21