define(['angular', 'modelFactory'], function (angular) {

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

    module.factory('ZooModel', function($modelFactory){
    
        var model = $modelFactory('api/zoo', {
            defaults: {
                newAnimal: true
            },
            actions: {
                query: {
                    cache: true
                },
                $copy: {
                    method: 'POST',
                    url: 'copy'
                }
            }
        });

        return model;
    });

    module.config(function ($stateProvider) {
        $stateProvider.state('zoo', {
            url: '/zoo',
            templateUrl: 'zoo.tpl.html',
            controller: 'ZooCtrl',
            resolve: {
                zoos: function (ZooModel) {
                    return ZooModel.query();
                }
            }
        });
    });

    module.controller('ZooCtrl', function ($scope, ZooModel, zoos) {

        //-> zoos = [ ZooModel({ type: 'National', name: 'DC Zoo', id: '123' }) ]
        $scope.zoos = zoos;

        $scope.editZoo = function(zoo){
            // UPDATE since we have an id
            zoo.$save().then(function(model){

                // cache was invalidated
                alert('Zoo was updated');
            });
        };

        $scope.deleteZoo = function(zoo){
            zoo.$destroy().then(function(){

                // cache was invalidated
                alert('Zoo was deleted');

                // zoo was automatically removed from array
                //-> $scope.zoos = [];
            });
        };

        $scope.createZoo = function(name){
            var newZoo = new ZooModel({
                name: name
            });

            // POST since no id
            zooModel.$save().then(function(model){
                //-> ZooModel({ name: 'whatever', newAnimal: true })

                // push our new zoo into the model
                // this will relate the zoo to the model
                // so if a user destorys this model it will
                // automatically be removed from the array too
                $scope.zoos.push(model);
            });
        };

        $scope.getZoo = function(id){
            // get a zoo by id
            ZooModel.get(id).then(function(model){
                $scope.newZoo = model;
            });
        };

        $scope.getPandas = function(){
            // get a zoo by animalType of panda
            // GET api/zoo?animalType=panda
            ZooModel.query({ animalType: 'panda' }).then(function(models){
                $scope.pandas = models;
            });
        };

        $scope.refreshZoos = function(){
            ZooModel.query().then(function(models){
                // models = [ ZooModel({ type: 'National', name: 'DC Zoo', id: '123' }) ]
                $scope.allZoos = models;
            });
        };

    });

    return module;
});
@@ -110,16 +110,280 @@
 tory'%5D);
+%0A    %0A    module.factory('AnimalModel', function() %7B%0A        function Animal(val) %7B%0A            angular.extend(this, val);%0A        %7D;%0A%0A        Animal.prototype.dateAdded = function(val) %7B%0A            return new Date(val);%0A        %7D;%0A%0A        return Animal;%0A    %7D);
 %0A%0A    mo
@@ -429,16 +429,29 @@
 lFactory
+, AnimalModel
 )%7B%0A    %0A
@@ -560,32 +560,212 @@
 %0A            %7D,%0A
+            map: %7B%0A                animals: function(animal)%7B%0A                    return animal.map(function(a)%7B return new AnimalModel(a); %7D)%0A                %7D    %0A            %7D,%0A
             acti
@@ -3409,8 +3409,9 @@
 ule;%0A%7D);
+%0A

Update simple.js