AngularJS Controllers - Controller Methods

· 8년 전 · 1323
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,597
AngularJS 8년 전 조회 1,443
AngularJS 8년 전 조회 1,315
AngularJS 8년 전 조회 1,754
AngularJS 8년 전 조회 1,206
AngularJS 8년 전 조회 1,606
AngularJS 8년 전 조회 1,533
AngularJS 8년 전 조회 1,234
AngularJS 8년 전 조회 1,776
AngularJS 8년 전 조회 1,799
AngularJS 8년 전 조회 1,226
AngularJS 8년 전 조회 1,388
AngularJS 8년 전 조회 1,502
AngularJS 8년 전 조회 1,297
AngularJS 8년 전 조회 1,324
AngularJS 8년 전 조회 1,309
AngularJS 8년 전 조회 1,452
AngularJS 8년 전 조회 1,335
AngularJS 8년 전 조회 1,562
AngularJS 8년 전 조회 1,286
AngularJS 8년 전 조회 1,186
AngularJS 8년 전 조회 1,267
AngularJS 8년 전 조회 1,801
AngularJS 8년 전 조회 1,510
AngularJS 8년 전 조회 1,607
AngularJS 8년 전 조회 1,239
AngularJS 8년 전 조회 1,496
AngularJS 8년 전 조회 1,590
AngularJS 8년 전 조회 1,581
AngularJS 8년 전 조회 2,220