■ ng-click안에서 $scope변수를 변경하고 ng-style에서는 $scope변수를 비교하는 조건문이 들어가는 ng-style 디렉티브 예제이다. 아래 코드에서 ng-click에서는 colorVal 값을 1,2,3으로 변경한다. 그리고 각 ng-style에서는 colorVal값을 비교하여 버튼의 배경색상을 변경한다.
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"> </script> <script type="text/javascript"> var app = angular.module('myApp', []) app.controller('myCtrl', function ($scope) { }); </script> <div ng-app="myApp" ng-controller="myCtrl"> <button type="button" ng-click="colorVal=1" ng-style="{'background-color':colorVal==1?'#ffd455':'#dddddd'}" style="width:100px;height:50px;font-size:smaller;"> <span>AAA</span> </button> <button type="button" ng-click="colorVal=2" ng-style="{'background-color':colorVal==2?'#ffd455':'#dddddd'}" style="width:100px;height:50px;font-size:smaller;"> <span>BBB</span> </button> <button type="button" ng-click="colorVal=3" ng-style="{'background-color':colorVal==3?'#ffd455':'#dddddd'}" style="width:100px;height:50px;font-size:smaller;"> <span>CCC</span> </button> </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일