I've create this piece of code:
app.controller('SiteDetailCtrl',function($scope, $routeParams, $http){
//remove ":" in SiteId
var SiteId = $routeParams.SiteId.replace(':','');
$scope.Site = $http.get('path-to-ajax/Site/'+SiteId);
.success(function(data){
$scope.Site = data;
console.log($scope.Site);
})
.error(function(){
$scope.Site = 'NULL';
alert('Ajax Fail');
});
console.log($scope.Site);
});
I don't understand why $scope.Site
is available in Success
function but outside ($http
) $scope.Site
is null
.
Please explain for me what happen here.
I'm new to AngularJS
.