Created
September 29, 2012 11:54
-
-
Save pjsvis/3803792 to your computer and use it in GitHub Desktop.
Project Module which uses Mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('project', ['mongolab']). | |
config(function($routeProvider) { | |
$routeProvider. | |
when('/', {controller:ListCtrl, templateUrl:'list.html'}). | |
when('/edit/:projectId', {controller:EditCtrl, templateUrl:'detail.html'}). | |
when('/new', {controller:CreateCtrl, templateUrl:'detail.html'}). | |
otherwise({redirectTo:'/'}); | |
}); | |
function ListCtrl($scope, Project) { | |
$scope.projects = Project.query(); | |
} | |
function CreateCtrl($scope, $location, Project) { | |
$scope.save = function() { | |
Project.save($scope.project, function(project) { | |
$location.path('/edit/' + project._id.$oid); | |
}); | |
} | |
} | |
function EditCtrl($scope, $location, $routeParams, Project) { | |
var self = this; | |
Project.get({id: $routeParams.projectId}, function(project) { | |
self.original = project; | |
$scope.project = new Project(self.original); | |
}); | |
$scope.isClean = function() { | |
return angular.equals(self.original, $scope.project); | |
} | |
$scope.destroy = function() { | |
self.original.destroy(function() { | |
$location.path('/list'); | |
}); | |
}; | |
$scope.save = function() { | |
$scope.project.update(function() { | |
$location.path('/'); | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment