앵귤러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 에 있는 변수에 값이 저장되게 되죠.
게시판 목록
퍼블리싱강좌
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 148 | AngularJS | 8년 전 | 1665 | ||
| 147 | AngularJS | 8년 전 | 1082 | ||
| 146 | AngularJS | 8년 전 | 1267 | ||
| 145 | AngularJS | 8년 전 | 1374 | ||
| 144 | AngularJS | 8년 전 | 1164 | ||
| 143 | AngularJS | 8년 전 | 1208 | ||
| 142 | AngularJS | 8년 전 | 1176 | ||
| 141 | AngularJS | 8년 전 | 1338 | ||
| 140 | AngularJS | 8년 전 | 1204 | ||
| 139 | AngularJS | 8년 전 | 1452 | ||
| 138 | AngularJS | 8년 전 | 1157 | ||
| 137 | AngularJS | 8년 전 | 1068 | ||
| 136 | AngularJS | 8년 전 | 1171 | ||
| 135 | AngularJS | 8년 전 | 1686 | ||
| 134 | AngularJS | 8년 전 | 1394 | ||
| 133 | AngularJS | 8년 전 | 1486 | ||
| 132 | AngularJS | 8년 전 | 1105 | ||
| 131 | AngularJS | 8년 전 | 1379 | ||
| 130 | AngularJS | 8년 전 | 1467 | ||
| 129 | AngularJS | 8년 전 | 1450 | ||
| 128 | AngularJS | 8년 전 | 2076 | ||
| 127 | AngularJS | 8년 전 | 1500 | ||
| 126 | jQuery Mobile | 8년 전 | 2270 | ||
| 125 | jQuery Mobile | 8년 전 | 2029 | ||
| 124 | jQuery Mobile | 8년 전 | 1892 | ||
| 123 | jQuery Mobile | 8년 전 | 1825 | ||
| 122 | jQuery Mobile | 8년 전 | 1863 | ||
| 121 | jQuery Mobile | 8년 전 | 2068 | ||
| 120 | jQuery Mobile | 8년 전 | 1602 | ||
| 119 | jQuery Mobile | 8년 전 | 1682 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기