AngularJS Hello World

In this example, we do a very simple AngularJS example.

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script>
<div ng-controller='MyController'>
    <!-- name model value is inserted below -->
    <h1>Hello, {{ person.name }}!</h1>
    <!-- name model value can be set by this <input> -->
    <input type="text" ng-model="person.name"></input>
</div>

JavaScript

// <body ng-app='myApp' binds to the app being created below.
var app = angular.module('myApp', []);

// Register MyController object to this app
app.controller('MyController', ['$scope', MyController]);    

// We define a simple controller constructor.
function MyController($scope) {
    // On controller load, assign 'World' to the "name" model
    // in <input type="text" ng-model="name"></input>
    $scope.person = {};
    $scope.person.name = 'Jose';
    $scope.person.lastName = 'Silva';
    var x = angular.copy($scope.person);
    x.name = 'João';
    alert(x.name);
    alert(JSON.stringify(x));
}