search

Home  >  Q&A  >  body text

angular.js - angularJS 点击显示,然后再点击消失怎么用.directive 指令做。

$scope.facePanel = false;

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

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-05-15 17:02:04

    How can you click on the element to display it again if it is already hidden?
    If you click a button to hide another element, it is still easy to implement!
    html

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

    No need for functions, just change it a little
    <button ng-click="$scope.facePanel=!$scope.facePanel">click</button>

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-15 17:02:04

    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>

    reply
    0
  • Cancelreply