ng-show和ng-hide不起作用

时间:2016-10-20 08:58:03

标签: javascript jquery angularjs

我的问题可能很简单。我想隐藏我家的所有页面上的介绍部分。 问题是,当您隐藏在每个页面上以及在每个页面上显示节目时。我打算隐藏在主页" /"。

HTML:

<!--  Intro Section --> 
<section id="intro" class="intro-section" ng-show="home">
    <div class="container">
        <div class="row">
            <a class="btn btn-default page-scroll scroll_btn floating" href="#slide">
                <span class="glyphicon glyphicon-arrow-down"></span>
            </a>
        </div>
    </div>
</section>

JS:

app.controller("employerCtrl", ["$scope", "$location", "$route", function($scope, $location, $route) {


    var path = $location.path();
    console.log(path);
    $scope.home = true;
    if(path === "/") {
        console.log("Inside");
        $scope.home = true;
    } else {
        console.log("Inside else");
        $scope.home = false;
    }


}]); 

1 个答案:

答案 0 :(得分:1)

home为根范围,在false控制器中设为home,在other控制器设为真。

app.controller("homecontroller", ["$scope", "$location", "$route","$rootScope", function($scope, $location, $route,$rootScope) {
        $rootScope.home = false;
}]); 

app.controller("othercontroller", ["$scope", "$location", "$route","$rootScope", function($scope, $location, $route,$rootScope) {
        $rootScope.home = true;
}]); 


<section id="intro" class="intro-section" ng-show="home">
    <div class="container">
        <div class="row">
            <a class="btn btn-default page-scroll scroll_btn floating" href="#slide">
                <span class="glyphicon glyphicon-arrow-down"></span>
            </a>
        </div>
    </div>
</section>