I have an application that looks like such:
var app = angular.module('app', []);
app.Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
app.controller = function('myController', function($scope) {
$scope.pageData = [];
$scope.pageData.firstName = ['John'];
$scope.pageData.lastName = ['Smith'];
$scope.pageData.people = [];
// just a demo. The point of this is just to show the controller creating Person objects
// assume that first name and last name will always be the same length;
for (var i = 0; i < firstName.length; i++) {
$scope.pageData.people.push(new Person($scope.pageData.firstName[i], $scope.pageData.lastName[i]);
}
});
Is there a better way of structuring Person
? Should it be in a factory or service?