앵귤러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 에 있는 변수에 값이 저장되게 되죠.
오늘은 앵귤러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 에 있는 변수에 값이 저장되게 되죠.
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 178 | AngularJS | 8년 전 | 1423 | ||
| 177 | AngularJS | 8년 전 | 1197 | ||
| 176 | AngularJS | 8년 전 | 1271 | ||
| 175 | AngularJS | 8년 전 | 1362 | ||
| 174 | AngularJS | 8년 전 | 1136 | ||
| 173 | AngularJS | 8년 전 | 1877 | ||
| 172 | AngularJS | 8년 전 | 1431 | ||
| 171 | AngularJS | 8년 전 | 1127 | ||
| 170 | AngularJS | 8년 전 | 1389 | ||
| 169 | AngularJS | 8년 전 | 1186 | ||
| 168 | AngularJS | 8년 전 | 999 | ||
| 167 | AngularJS | 8년 전 | 1961 | ||
| 166 | AngularJS | 8년 전 | 1035 | ||
| 165 | AngularJS | 8년 전 | 1099 | ||
| 164 | AngularJS | 8년 전 | 1303 | ||
| 163 | AngularJS | 8년 전 | 1149 | ||
| 162 | AngularJS | 8년 전 | 1362 | ||
| 161 | AngularJS | 8년 전 | 1367 | ||
| 160 | AngularJS | 8년 전 | 1121 | ||
| 159 | AngularJS | 8년 전 | 1088 | ||
| 158 | AngularJS | 8년 전 | 1500 | ||
| 157 | AngularJS | 8년 전 | 1471 | ||
| 156 | AngularJS | 8년 전 | 1320 | ||
| 155 | AngularJS | 8년 전 | 1209 | ||
| 154 | AngularJS | 8년 전 | 1608 | ||
| 153 | AngularJS | 8년 전 | 1073 | ||
| 152 | AngularJS | 8년 전 | 1481 | ||
| 151 | AngularJS | 8년 전 | 1412 | ||
| 150 | AngularJS | 8년 전 | 1107 | ||
| 149 | AngularJS | 8년 전 | 1637 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기