AngularJS Controllers - Controller Methods

· 8년 전 · 1222
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,488
AngularJS 8년 전 조회 1,328
AngularJS 8년 전 조회 1,219
AngularJS 8년 전 조회 1,629
AngularJS 8년 전 조회 1,092
AngularJS 8년 전 조회 1,503
AngularJS 8년 전 조회 1,435
AngularJS 8년 전 조회 1,126
AngularJS 8년 전 조회 1,656
AngularJS 8년 전 조회 1,693
AngularJS 8년 전 조회 1,102
AngularJS 8년 전 조회 1,282
AngularJS 8년 전 조회 1,392
AngularJS 8년 전 조회 1,181
AngularJS 8년 전 조회 1,223
AngularJS 8년 전 조회 1,196
AngularJS 8년 전 조회 1,351
AngularJS 8년 전 조회 1,212
AngularJS 8년 전 조회 1,464
AngularJS 8년 전 조회 1,172
AngularJS 8년 전 조회 1,080
AngularJS 8년 전 조회 1,164
AngularJS 8년 전 조회 1,688
AngularJS 8년 전 조회 1,406
AngularJS 8년 전 조회 1,505
AngularJS 8년 전 조회 1,129
AngularJS 8년 전 조회 1,401
AngularJS 8년 전 조회 1,491
AngularJS 8년 전 조회 1,476
AngularJS 8년 전 조회 2,103
🐛 버그신고