AngularJS绑定值为NgShow和NgHide

时间:2017-02-01 16:48:25

标签: javascript angularjs

我正在尝试使用数组来显示和隐藏使用ng-show和ng-hide的div。它似乎并不一致。当我使用控制台检查值时,它们是正确的,但它们在HTML中没有正确反映。

<div class="directionsContent" ng-show="showvars.directions" ng-hide="!showvars.directions">
    <h1 class="directionsTitle">DIRECTIONS TO:</h1>
    <h3>{{directions.title}}</h3>
    <div id="directionsPanel"></div>
</div>

使用的功能是:

$scope.ShowMobile = function (showsection) {

    console.log(showsection)
    for (prop in $scope.showvars) {
        console.log(prop, $scope.showvars[prop])
        if (showsection != "return" && showsection != "info") {
            $scope.showvars[prop] = false;
        }
    }

    switch (showsection) {
        case "explore": 
            $scope.showvars.explore = true;
            break;
        case "directions":
            $scope.showvars.explore = true;
            $scope.showvars.directions = true;
            break;
        case "tourlist":
            $scope.showvars.explore = true;
            $scope.showvars.tourlist = true;
            break;
        case "tourdetail":
            $scope.showvars.explore = true;
            $scope.showvars.tourdetail = true;
            break;
        case "tour":
            $scope.showvars.explore = true;
            $scope.showvars.tour = true;
            break;
        case "nearby":
            $scope.showvars.explore = true;
            $scope.showvars.nearby = true;
            break;
        case "info":
            $scope.showvars.explore = false;
            $scope.showvars.info = true;
            break;
        case "search":
            $scope.showvars.search = true;
            break;
        case "return":
            $scope.showvars.explore = true;
            $scope.showvars.info = false;
            $scope.showvars.search = false;
            break;
        default:
            break;
    }

    console.log($scope.showvars)


}

这是代码,遗憾的是它没有一个有效的例子。

https://jsfiddle.net/jpking72/61cfyre8/

0 个答案:

没有答案