123456789101112131415161718192021222324252627282930313233 |
- angular.module("noteWrangler")
- .controller("NoteCreateController", function ($http) {
- const controller = this;
- this.saveNote = function (note) {
- controller.errors = null;
- $http({
- method: "POST",
- url: "/notes.json",
- data: note,
- }).catch(function (note) {
- controller.errors = note.data.error;
- })
- .then(responseHandler, errorHandler);
- };
- const errorHandler = function (err) {
- console.log("Error getting /notes", err);
- };
- const responseHandler = function (data) {
- controller.notes = data.data;
- };
- });
- /* Somewhere in templates, to show the error:
- <p ng-if="createController.errors">
- {{ createController.errors }}
- </p>
- */
|