1

Very simple form with only one input - "Name". However, I do not want duplicates in the table.

On the server side I can check this, and pass a custom message to the response header "Name already Exists".

How do I go about getting the save() method in my angular controller to see this message and pass an alert('Name already exists') ?

Thanks all.

What is to show??

You open the form in Chrome, select developer tools, then network. Put a name you already know is in the database, click Submit, then click on the API, then the response tab where my server passed the message "Name already exists".

I just need to know how to get Angular in the save method to pick up that message. Angular knows the data wasn't saved; it stays on the form, but the user has no clue why he/she hasn't moved off the form after submit. I need them to see that the name is already in the db.

grendian

Thanks for your response, I think you are on to something. I will try that tomorrow and get back to you.

2
  • 1
    Show us what you have so far. Commented Feb 25, 2013 at 21:53
  • where is your form submit code? Hard to help without any code provided Commented Feb 25, 2013 at 23:10

2 Answers 2

1

You can use callbacks on resource methods for success and fail.

resource.save(function(data){
    console.log('saved with response:', data);
}, function(err){
    console.log('failed with response:', data);
});
Sign up to request clarification or add additional context in comments.

Comments

0

I was not able to find a solution via my API resources so I decided to use $http which the below does indeed work:

$scope.save = function () {

$http.post('/api/TruckMfgs/', $scope.truckMfg)  
    .success(function () {
    })
    .error(function (data) {
        alert(data);
    });

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.