AngularJS - Controller As Syntax

by Luiza CICONE

HTML

<link rel="stylesheet" href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css">
<script src="http://code.angularjs.org/1.1.5/angular.js"></script>
<div ng-app="myapp">
    <fieldset ng-controller="PersonCtrl as person">
        <input type="text" ng-model="person.first"><input type="text" ng-model="person.last">
        <p>{{ person.fullName() }}</p>
    </fieldset>
</div>

JavaScript

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

myapp.controller('PersonCtrl', function () {
    this.first = 'First';
    this.last = 'Last';
    this.fullName = function() {
        return this.first + ' ' + this.last;
    };
});