AngularJS Controllers - Controller Methods

· 8년 전 · 1332
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>
|
댓글을 작성하시려면 로그인이 필요합니다.

퍼블리싱강좌

+
분류 제목 글쓴이 날짜 조회
AngularJS 8년 전 조회 1,611
AngularJS 8년 전 조회 1,454
AngularJS 8년 전 조회 1,326
AngularJS 8년 전 조회 1,761
AngularJS 8년 전 조회 1,213
AngularJS 8년 전 조회 1,621
AngularJS 8년 전 조회 1,545
AngularJS 8년 전 조회 1,246
AngularJS 8년 전 조회 1,784
AngularJS 8년 전 조회 1,808
AngularJS 8년 전 조회 1,238
AngularJS 8년 전 조회 1,399
AngularJS 8년 전 조회 1,507
AngularJS 8년 전 조회 1,302
AngularJS 8년 전 조회 1,333
AngularJS 8년 전 조회 1,315
AngularJS 8년 전 조회 1,460
AngularJS 8년 전 조회 1,343
AngularJS 8년 전 조회 1,570
AngularJS 8년 전 조회 1,291
AngularJS 8년 전 조회 1,201
AngularJS 8년 전 조회 1,278
AngularJS 8년 전 조회 1,806
AngularJS 8년 전 조회 1,523
AngularJS 8년 전 조회 1,620
AngularJS 8년 전 조회 1,247
AngularJS 8년 전 조회 1,502
AngularJS 8년 전 조회 1,597
AngularJS 8년 전 조회 1,595
AngularJS 8년 전 조회 2,231