Sử dụng AngularJS Controllers

* Ví dụ:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="control_nhanvien">
Họ: <input type="text" ng-model="Ho"><br>
Tên: <input type="text" ng-model="Ten"><br>
<br>
Full Name: {{HoTenDayDu()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('control_nhanvien', function($scope) {
    $scope.Ho = "Hồng";
    $scope.Ten = "Nhật";
    $scope.HoTenDayDu = function() {
        return $scope.Ho + " " + $scope.Ten;
    };
});
</script>
</body>
</html>

Giải thích: ngoài cách ng-model để tham chiếu giá trị, ta có thể xử lý riêng 1 biến như ví dụ trên
$scope.HoTenDayDu = function() {
        return $scope.Ho + " " + $scope.Ten;
    };


- Để truy cập nó chỉ cần sử dụng {{ HoTenDayDu() }}

* Cách sử dụng controller riêng ra 1 file
Tạo 1 file Javascript có tên control_nhanvien.sj
var app = angular.module('myApp', []);
app.controller('control_nhanvien', function($scope) {
    $scope.Ho = "Hồng";
    $scope.Ten = "Nhật";
    $scope.HoTenDayDu = function() {
        return $scope.Ho + " " + $scope.Ten;
    };
});

Sau đó <script src="control_nhanvien.js"></script> là xong.

Cụ thể:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="control_nhanvien">
Họ: <input type="text" ng-model="Ho"><br>
Tên: <input type="text" ng-model="Ten"><br>
<br>
Full Name: {{HoTenDayDu()}}
</div>
<script src="control_nhanvien.js"></script>
</body>
</html>