Angular 문법 정리
본문 바로가기

Frontend/Angular

Angular 문법 정리

준비

ng-app, ng-controller을 상위 태그에 삽입

var app = angular.module('alpp',[])
app.controller("alpo", function($scope){
    ...
})

변수나 함수는 무조건 $scope.로 시작한다.

 

클릭 이벤트

<button ng-click="myFunc('test')" type="button" class="btn btn-danger">ACTIVE</button>
$scope.myFunc = (text) => {
    alert(text)
}

 

문법

* 변수

* if문

만약 $scope.name이 없으면 loading...이라는 문구가 표시되고 보이면 사라짐

<p ng-if="!name">loading...</p>

비슷하게 $scope.name이 없을경우 ng-disabled를 활용해 태그를 비활성화시킬 수 있다.

<input ng-model="name" ng-disabled="!name"/></div>

* for 반복문

 

참고

https://www.youtube.com/watch?v=ywHk2jf_lF8

반응형