set $scope on ajax callback is OK

by victorwoo

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">{{greeting}}</div>

JavaScript

var myApp = angular.module('myApp', []);

var data = {
    foo: 'bar'
};

function MyCtrl($scope, $http) {
    $scope.greeting = 'init';
    $http.post('/echo/json/', 'json=' + encodeURIComponent(angular.toJson(data)), {
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    }).success(function (data) {
        console.log('update greeting');
        $scope.greeting = 'hello'; // it works.
    });
}