Skip to content

Instantly share code, notes, and snippets.

@fguisso
Created May 11, 2016 18:49
Show Gist options
  • Save fguisso/c4f187efe8955fc503cda0a99df5f3b3 to your computer and use it in GitHub Desktop.
Save fguisso/c4f187efe8955fc503cda0a99df5f3b3 to your computer and use it in GitHub Desktop.
Angular http.post
<div id="todo-form" class="row">
<div class="col-sm-8 col-sm-offset-2 text-center">
<form>
<div class="form-group">
<input type="text" class="form-control input-lg text-center" placeholder="Digite uma tarefa." ng-model="formData.item">
</div>
<button type="submit" class="btn btn-primary btn-lg" ng-click="createItem()">Add</button>
</form>
</div>
</div>
$scope.createItem = function(){
$http.post('/api/itens', $scope.formData)
.success(function(data){
$scope.formData = {};
$scope.todos = data;
console.log(data);
})
.error(function(data){
console.log('Error: ' + data);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment