Skip to content

Instantly share code, notes, and snippets.

@kauffmanes
Last active August 15, 2017 16:28
Show Gist options
  • Save kauffmanes/3d5e8d5f1ad08d9bba15a70ba396fb6b to your computer and use it in GitHub Desktop.
Save kauffmanes/3d5e8d5f1ad08d9bba15a70ba396fb6b to your computer and use it in GitHub Desktop.
Form Controller 1
var app = angular.module('app', []);
app.controller('FormController', ['$scope', function ($scope) {
$scope.questions = [];
//Again, can be fired on a button click, on page load, etc.
$scope.getQuestions = function (type) {
var type = type ? type : 'default'; //some kind of validation can go here
//make service call based on category and return questions
$http({
method: 'GET',
url: '/forms',
params: { name: type }
}).then(function (res) {
//Parse response to get just questions collection
$scope.questions = res && res.data && res.data.questions;
})['finally'](function (err) {
//Error handling
});
};
$scope.submit = function () {
//submit form data
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment