Reputation: 97
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;
});
};
Upvotes: 2
Views: 1791
Reputation: 26
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.
Upvotes: 1
Reputation: 97
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!!
Upvotes: 1