0

I want to use ng-hide in the index page if the url in some nested views. in my index.html, I want something like:

    <top-bar ng-if="!home"></top-bar>
    <ui-view class="reveal-animation"></ui-view>
    <bottom-bar ng-if="!home"></bottom-bar>

I want that when I enter to "home" view the bars will disappeared. as I saw here in same questions - the answer was to use $location in the controller, but where is the controller of the index page?

thanks

4

2 回答 2

2

在父控制器中,添加以下内容:

$scope.isHome = function(){
  return $state.is("home");
}

然后像这样更改您的模板:

<top-bar ng-if="!isHome()"></top-bar>
<ui-view class="reveal-animation"></ui-view>
<bottom-bar ng-if="!isHome"></bottom-bar>

在此处查看此 plunkr以查看一些实时代码。


另一种方法是使用$stateChangeSuccess,如下所示:

$scope.$on("$stateChangeSuccess", function(event, toState){
  $scope.isHome = (toState.name == "home")
})

我还建议结帐$state.includes$state.current以及其他。只需通过此处的文档

于 2015-01-14T18:07:12.910 回答
0

一口气教你所有东西并不容易。你必须参考几个概念。

http://viralpatel.net/blogs/angularjs-routing-and-views-tutorial-with-example/

我希望这个链接能帮助你开始使用 Angularjs。

于 2015-01-14T18:02:30.260 回答