AngularJS Service Dependencies

by Edward Tanguay

HTML

<div ng-app="app">
    <div ng-controller="CalculatorController">
         <ul>
             <li ng-repeat="person in persons">
                 {{person.display()}}
             </li>
        </ul>
    </div>
</div>

CSS

body {
    font-family:sans-serif;
    background-color: #f5f5f5;
}
div {
    margin:20px 5px;
}

JavaScript

function Person(firstName, lastName) {
    this.firstName=firstName;
    this.lastName=lastName;
}

Person.prototype={
    display : function() {
			return this.lastName + ', ' + this.firstName;
        }
};

function Customer(firstName, lastName, company) {
    Person.call(this,firstName,lastName);
    this.company=company;
}

Customer.prototype=new Person();

Customer.prototype.display=function(){
    return Person.prototype.display.call(this)+' ('+ this.company+')';  
}

angular.module('app', [])
.controller('CalculatorController', function($scope) {
    $scope.persons = [];
    $scope.persons.push(new Person('Jim', 'Thompson'));
    $scope.persons.push(new Person('Jack', 'Harrison'));
    $scope.persons.push(new Customer('Mandy', 'Baker', 'Acme Inc.'));
});