angular.js - angularJS 点击显示,然后再点击消失怎么用.directive 指令做。
黄舟
黄舟 2017-05-15 17:00:04
0
2
556

$scope.facePanel = false;

    $scope.showFace = function () {
        $scope.facePanel = !$scope.facePanel;
    }
    这是我在controller里面的代码
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

Antworte allen(2)
洪涛

都隐藏了你还怎么点击元素再让显示?
如果是点击一个button让另一个元素隐藏的话还是很好实现的!
html

<button ng-click="showFace()">点击</button>
<p ng-show="facePanel">要显示或隐藏的元素</p>

不用函数了,稍微改下就行
<button ng-click="$scope.facePanel=!$scope.facePanel">点击</button>

伊谢尔伦

js

angular.directive('aDirective', [function(){
    return {
        restrict: 'E',
        template:'<p a-directive><p ng-show="facePanel">元素</p><button ng-click="showFace()">点击</button></p>',
        replace: true,
        link: function(scope, ele, attr){
            scope.facePanel = false;
            scope.showFace = function () {
                scope.facePanel = !$scope.facePanel;
            } 
        }
    }
}])

html

<a-directive></a-directive>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage