Skip to content

Instantly share code, notes, and snippets.

@johnsinco
Created May 10, 2013 19:19
Show Gist options
  • Save johnsinco/5556734 to your computer and use it in GitHub Desktop.
Save johnsinco/5556734 to your computer and use it in GitHub Desktop.
simple angularjs demo of a wizard flow (doesn't work)
angular.module('register', ['ngResource', 'rails']).
config(function($routeProvider) {
$routeProvider.
when('/', {controller:RegisterCtrl, templateUrl:'/partials/register.html'}).
when('/#profile', {controller:RegisterCtrl, templateUrl:'/partials/profile.html'}).
when('/#preferences', {controller:RegisterCtrl, templateUrl:'/partials/preferences.html'}).
otherwise({redirectTo:'/'});
});
angular.module('register').factory('User', ['railsResourceFactory', function (railsResourceFactory) {
return railsResourceFactory({url: '/users', name: 'user'});
}]);
var RegisterCtrl = function($scope, $location, User) {
$scope.user = new User();
$scope.createAccount = function() {
$scope.user.create();
$scope.step = "profile"
$location.path('/#profile');
}
$scope.completeProfile = function() {
$scope.user = User.get($scope.user.id).then(function(user) {
user.phone = $scope.user.phone
user.street = $scope.user.street
user.update();
});
$scope.step = "preferences"
$location.path('/#preferences');
}
$scope.confirm = function() {
$scope.user = User.save($scope.user)
$scope.step = "thanks"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment