如何在 index.html 页面中使用基于 url 的 ng-if?

问题描述 投票:0回答:2
javascript angularjs uiview ng-hide js-routes
2个回答
3
投票

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

$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
和其他人。只需阅读文档here


-1
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.