Marinescu Vlad Marinescu Vlad - 6 months ago 16
HTML Question

AngularJS getting error on Post method

I made an RESTful api in .net .The html is created with angularJS.

The problem is, when the page loads, i'm getting the following error:
enter image description here

and the "insert" button doesn't work anymore.

This is my insert script and the full html can be found at the link:

$scope.insert = function insert() {
var data = {"id": 3, "name": $scope.name, "description":$scope.description , "price": $scope.price, "categoryid": $scope.categoryid};
$http.post(
'http://localhost:22258/api/product',
JSON.stringify(data),
{
headers: {
'Content-Type': 'application/json'
}
}
).success(function (data) {
$scope.products.push(data);
});


https://jsfiddle.net/0xb2nh9o/

If you are kind to help me to make Edit button works as the following model: https://jsfiddle.net/benfosterdev/UWLFJ/ to make HTTPPut to api, it will be wonderful.

All Restful requests works, api works, tested with PostMan

I'm kinnda newbie to AngularJS so your help will be very useful for me. Thanks a lot !

Answer

Your insert function is part of 'ProductController', not 'FormCtrl'.

So in your html, do this:

<div ng-controller="ProductController">

and you will get rid of that error.

Comments