With the views finished, you need to implement the AngularJS controller code to support them. Listing 26.15 implements the AngularJS controller that supports the user
view. The controller, like the web forms, is very basic. The controller uses the $http
service to get the user data from the /user/profile
route and provide it to the AngularJS template in the $scope.user
value.
01 angular.module('myApp', []).
02 controller('myController', ['$scope', '$http',
03 function($scope, $http) {
04 $http.get('/user/profile')
05 .success(function(data, status, headers, config) {
06 $scope.user = data;
07 $scope.error = "";
08 }).
09 error(function(data, status, headers, config) {
10 $scope.user = {};
11 $scope.error = data;
12 });
13 }]);