AngularJS Controllers - Controller Methods
Controller Methods(컨트롤러 메소드)
위 예제는 lastName과 firstName의 두 가지 속성을 가진 컨트롤러 객체를 보여줍니다.
컨트롤러는 메소드 (변수를 함수로)를 가질 수도 있습니다 :
<div ng-app="myApp" ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
};
});
</script>
전체소스
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
};
});
</script>
</body>
</html>
'IT > 앵귤러js' 카테고리의 다른 글
앵귤러js Filters uppercase AngularJS Filters uppercase (0) | 2017.08.08 |
---|---|
AngularJS Controllers - Controllers In External Files (0) | 2017.08.06 |
AngularJS Controllers (0) | 2017.08.06 |
AngularJS Directives(지시문) - Repeating HTML Elements(반복되는 HTML 요소) (0) | 2017.08.03 |
AngularJS Directives(지시문) - 데이터 바인딩 (0) | 2017.08.03 |