ng-if =“ hideDiv”,其中hideDiv = false不会隐藏div

时间:2018-11-06 01:35:30

标签: angularjs

我必须在单击时隐藏div。

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"  
ExpiresByType application/javascript "access 1 month"  
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]

ErrorDocument 404 https://website.com/404.php

控制器

<div ng-if="hideDiv">
<div>text text text text</div>
<a ng-click="hideMe(false)">Click Me To Hide</a>
</div>

测试结果是

this.hideMe = function(action){
 $scope.hideDiv = action;
}

但是ng-if是否不隐藏div?

1 个答案:

答案 0 :(得分:3)

请测试以下代码段。我很确定您的问题是由于一些angularJS配置失败

(function(){
    angular.module("app", []).controller("testController", function($scope)
    {
        $scope.showDiv = true;

        $scope.hideMe = function(IsVisible)
        {
            $scope.showDiv = IsVisible;
        }
    });
})();
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="testController">
    <div ng-if="showDiv">
        <a ng-click="hideMe(false)">Click Me To Hide</a>
    </div>
</div>