Created
May 11, 2016 18:49
-
-
Save fguisso/c4f187efe8955fc503cda0a99df5f3b3 to your computer and use it in GitHub Desktop.
Angular http.post
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
<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> |
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
$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