앵귤러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년 전 | 1434 | ||
| 177 | AngularJS | 8년 전 | 1206 | ||
| 176 | AngularJS | 8년 전 | 1275 | ||
| 175 | AngularJS | 8년 전 | 1371 | ||
| 174 | AngularJS | 8년 전 | 1143 | ||
| 173 | AngularJS | 8년 전 | 1885 | ||
| 172 | AngularJS | 8년 전 | 1440 | ||
| 171 | AngularJS | 8년 전 | 1131 | ||
| 170 | AngularJS | 8년 전 | 1395 | ||
| 169 | AngularJS | 8년 전 | 1191 | ||
| 168 | AngularJS | 8년 전 | 1005 | ||
| 167 | AngularJS | 8년 전 | 1970 | ||
| 166 | AngularJS | 8년 전 | 1042 | ||
| 165 | AngularJS | 8년 전 | 1110 | ||
| 164 | AngularJS | 8년 전 | 1312 | ||
| 163 | AngularJS | 8년 전 | 1157 | ||
| 162 | AngularJS | 8년 전 | 1371 | ||
| 161 | AngularJS | 8년 전 | 1380 | ||
| 160 | AngularJS | 8년 전 | 1132 | ||
| 159 | AngularJS | 8년 전 | 1096 | ||
| 158 | AngularJS | 8년 전 | 1514 | ||
| 157 | AngularJS | 8년 전 | 1482 | ||
| 156 | AngularJS | 8년 전 | 1327 | ||
| 155 | AngularJS | 8년 전 | 1215 | ||
| 154 | AngularJS | 8년 전 | 1621 | ||
| 153 | AngularJS | 8년 전 | 1112 | ||
| 152 | AngularJS | 8년 전 | 1533 | ||
| 151 | AngularJS | 8년 전 | 1425 | ||
| 150 | AngularJS | 8년 전 | 1123 | ||
| 149 | AngularJS | 8년 전 | 1647 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기