앵귤러js controller

앵귤러js 컨트롤러 controller

오늘은 앵귤러js에 controller 에 대해 알아볼게요

컨트롤러는 데이터를 조작하는데 사용하게 됩니다.
앵귤러js에 directive 중 ng-controller 가 있고 $scope이라는 parameter가 있습니다.


<html>
<head>
<title>앵귤러 controller </title>
<meta charset="UTF-8">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<div ng-app= "initApp" ng-controller="productController">
메뉴이름 : <input type="text" ng-model="product.productName"><br><br>
가격 : <input type="text" ng-model="product.price"><br><br>

현재 입력한 값 : {{product.productList()}}
</div>

<script>
var initApp = angular.module("initApp", []);

initApp.controller('productController', function($scope){
$scope.product={
productName:"라면",
price:"7000",

productList:function(){
var productObject;
productObject = $scope.product;
return productObject.productName+" "+productObject.price + "원";
}
};
});
</script>
</body>
</html>

ng-app는 앵귤러js에 시작입니다. 시작하면서 initApp를 실행하게 됩니다.

productName:"라면",
price:"7000",

이 곳에서 초기값을 설정하게 되죠.
ng-controller 에 "productController" 와 initApp.controller('productController', function($scope){

productController가 매핑이 되면서 사용가능하게 되는 것입니다.

input box에 ng-model이 controller에 바인딩 되어 controller 에 있는 변수에 값이 저장되게 되죠.
|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

퍼블리싱강좌

+
분류 제목 글쓴이 날짜 조회
jQuery Mobile 8년 전 조회 1,992
jQuery Mobile 8년 전 조회 1,517
jQuery Mobile 8년 전 조회 1,681
jQuery Mobile 8년 전 조회 1,794
jQuery Mobile 8년 전 조회 1,665
jQuery Mobile 8년 전 조회 1,832
jQuery Mobile 8년 전 조회 1,469
jQuery Mobile 8년 전 조회 1,636
jQuery Mobile 8년 전 조회 2,193
jQuery Mobile 8년 전 조회 2,694
jQuery Mobile 9년 전 조회 2,141
jQuery Mobile 9년 전 조회 1,530
jQuery Mobile 9년 전 조회 2,430
AngularJS 9년 전 조회 2,898
AngularJS 9년 전 조회 2,466
AngularJS 9년 전 조회 1,803
AngularJS 9년 전 조회 2,869
AngularJS
[AngularJS]
9년 전 조회 2,430
반응형웹 9년 전 조회 4,515
반응형웹 9년 전 조회 7,594
부트스트랩 10년 전 조회 1.5만
부트스트랩 11년 전 조회 9,451
표준화 11년 전 조회 8,335
반응형웹 12년 전 조회 1.4만
표준화 12년 전 조회 9,528
표준화 13년 전 조회 1.7만
반응형웹 13년 전 조회 2만
반응형웹 13년 전 조회 3.1만
반응형웹 13년 전 조회 3.7만
표준화 13년 전 조회 1.3만
🐛 버그신고