Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to send a repeater array items to web api controller method as parameter. When I click the button containing the function its giving me this error in console and nothing happens.

object is not a function

I guess I'm passing the orders array in a wrong way. How to do that correctly.

My ng-repeat

    <table class="table table-bordered table-hover" style="width:800px" data-ng-model="orderProduct">
            <tr data-ng-repeat="order in orders">
                <td>{{selectedProduct.pname}}</td>
                <td>{{order.pid}}</td>
                <td>{{order.oid}}</td>
                <td>{{order.qty}}</td>
                <td>{{order.total}}</td>
            </tr>
        </table>
        <input type="button" data-ng-click="addOrder()" class="btn btn-danger" data-ng-disabled="!orders.length" value="Submit Orders" />

My controller method $scope

    $scope.addOrder = function () {
            var orders = this.orders;
            $http.post('/api/OrderDetails/', orders).success(function (data) {
                alert("Added Successfully!!");
                $scope.addMode = false;

            }).error(function (data) {
                $scope.error = "An Error has occured while Adding Order details! " + data;

            });
        };
share|improve this question
    
Do you have a stack trace? –  Andrew Eisenberg Jul 2 '14 at 5:00
    
will this work? pastebin.com/raw.php?i=m7KgcQQe –  coder Jul 2 '14 at 5:10
    
I recommend that you use the non-minimized version of angularjs during development. Much easier to debug. –  Andrew Eisenberg Jul 2 '14 at 5:13
    
I recommend that you start using Chrome Dev Tools, Firebug, or IE dev tools, open up your source code and step through the debugger. You will likely find something. –  Andrew Eisenberg Jul 2 '14 at 5:18
    
changed to nonminified version and got this in chrome pastebin.com/raw.php?i=J3gvMqGz –  coder Jul 2 '14 at 5:19

2 Answers 2

up vote 0 down vote accepted

What I figured from your plunk is that - the form-name and a controller's method name can not be the same. I changed the form-name from addOrder to addOrderForm Once the names have changed, this works correctly. Please see working plunk here: http://plnkr.co/edit/CfaNY9z5vVMi5uqh5v7k?p=preview

PS: I've taken the liberty of adding some json and angular code to get the form working.

share|improve this answer
    
#coder I see that you've posted your own answer :) –  Jaya Jul 2 '14 at 7:48
    
but your answer is more precisely described with the reason of why this happened. Thank you –  coder Jul 6 '14 at 18:24

After thinking for a while about the line

object is not a valid function

and the other error from firefox

fnPtr is not a function

It suddenly buzzed in my mind that there maybe something fishy with my function naming. I guess it's silly but after changing the function name from addOrder() to addorder(), that is after replacing the capital 'O' with small 'o' the error has gone and everything working smoothly. Peace!!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.