■ 토글방식 보이기/숨기기
11번째 라인에서 showHide의 값이 true이므로 18번째 라인의 div의 ng-show값이 true가 되어서 div의 내용이 보이게 된다. Show/Hide버튼을 클릭하게 되면 showHide의 값이 false, ng-show값이 false 가 되어서 div의 내용이 보이지 않게 된다. 버튼을 클릭하게 되면 showHide=!showHide가 showHide값을 반전(?)시켜서 div가 보기기/숨기기가 구현된다.
<!DOCTYPE html> <html ng-app="myApp"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8"> <head> <title></title> <script src="/js/angularjs/1.5.6/angular.js"></script> <script> var myApp = angular.module("myApp",[]); myApp.controller("myAppCtrl",["$scope", function($scope){ $scope.showHide = true; }]); </script> </head> <body ng-controller="myAppCtrl"> <h1>토글방식 보이기/숨기기 <br><font color="red">ng-click="showHide=!showHide"</font></h1> <button ng-click="showHide=!showHide">Show/Hide</button> <div ng-show="showHide">Show/Hide 보이기/숨기기</div> </body> </html>
■ 함수방식 보이기/숨기기
11번째 라인에서 showHide값이 true이므로 div가 보인다. 버튼을 클릭하면 showHideToggle함수를 호출해서 showHide값을 true이면 false로, false이면 true로 변경되어서 div가 보이기/숨기기가 구현된다.
<!DOCTYPE html> <html ng-app="myApp"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta charset="utf-8"> <head> <title></title> <script src="/js/angularjs/1.5.6/angular.js"></script> <script> var myApp = angular.module("myApp",[]); myApp.controller("myAppCtrl",["$scope", function($scope){ $scope.showHide = true; $scope.showHideToggle = function() { if($scope.showHide==true) { $scope.showHide=false; } else { $scope.showHide=true; } }; }]); </script> </head> <body ng-controller="myAppCtrl"> <h1>함수방식 보이기/숨기기 <br><font color="red">ng-click="showHideToggle()"</font></h1> <button ng-click="showHideToggle()">Show/Hide</button> <div ng-show="showHide">Show/Hide 보이기/숨기기</div> </body> </html>
- AngularJS angular.copy 사용법, angular 복사 2019년 5월 17일
- AngularJS fromJson, toJson 사용법 2019년 5월 15일
- AngularJS에서 ng-style사용시 조건문 이용방법 2019년 4월 25일
- AngularJS에서 ng-style사용시 함수 이용방법 2019년 4월 23일
- AngularJS 동적 HTML, Function 추가 2019년 4월 15일
- AngularJS에서 팝업창 띄우기 2019년 4월 2일
- AngularJS 하나의 모듈에 factory 다중 등록 2018년 2월 26일
- AngularJS factory 예제 2018년 2월 26일
- AngularJS forEach ng-repeat 예제 2018년 2월 19일
- AngularJS $http, spring TEXT response 예제 2018년 1월 17일
- AngularJS selectbox 간단한 예제 2018년 1월 15일
- AnuglarJS forEach 예제 2018년 1월 12일
- AngularJS checkbox 제어 및 활성/비활성(ng-disabled) 예제 2018년 1월 8일
- AngularJS button 활성/비활성(ng-disabled) 예제 2018년 1월 8일
- AngularJS radio 활성/비활성(ng-disabled) 예제 2018년 1월 8일
- AngularJS $broadcast, $emit, $on 예제 2018년 1월 3일
- AngularJS – $watch $digest $apply Life Cycle 2017년 12월 26일
- AngularJS $watchCollection 2017년 12월 26일
- AngularJS $watchGroup 2017년 12월 26일
- AngularJS $watch 2017년 12월 26일
- AngularJS 반복문 ng-repeat 2017년 7월 22일
- AngularJS $timeout 2017년 7월 22일
- AngularJS Show/Hide, 보이기/숨기기 2017년 7월 16일
- AngularJS 라디오 버튼 제어 2017년 7월 16일
- AngularJS시작하기, Hello AngularJS 2017년 7월 15일