I am trying to do a test app based on app from tutorial https://docs.angularjs.org/tutorial/step_00 . It works fine but I have with post method.
index.html
...
<div class="control_panel" ng-controller="phonecatControllers">
<button class="btn btn-default" ng-click="chiliSpicy()">Chili!</button>
<button class="btn btn-default" ng-click="sendData()">send!</button>
</div>
...
controllers.js
'use strict';
var phonecatControllers = angular.module('phonecatControllers', []);
phonecatControllers.controller('PhoneListCtrl', ['$scope', '$http', '$log',
function ($scope, $http, $log) {
$http.get('http://localhost:8080/webapp/rest/myresource/posts').
success(function (data) {
$scope.posts = data;
});
$scope.data = "hello world";
$scope.chiliSpicy = function () {
$log.info('chili function');
};
$scope.sendData = function () {
$http.post('http://localhost:8080/webapp/rest/myresource/', {'data' : $scope.data} )
.succes(function (data, status, headers, config) { // !!! here is line 39
$log.info('sent');
})
.error(function (data, status, headers, config) {
$log.error('not sent')
});
};
}]);
Get method works ok (showed html code does not contain its usage), also chiliSpicy function works. But sendData function throws error (where success function is)
TypeError: undefined is not a function
at l.$scope.sendData (http://localhost:8080/webapp/controllers.js:39:18)
at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:198:424
at chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:798:21
at l.$eval (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:84)
at l.$apply (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:126:310)
at l.scopePrototype.$apply (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:1478:22)
at HTMLButtonElement.<anonymous> (chrome-extension://ighdmehidhipcmcojjgiloacoafjmpfk/dist/hint.js:797:25)
at HTMLButtonElement.c (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js:32:363)
Actually, the server receives data, but success function do not pass. Any idea? Thanks.
Misspelled success
, written as succes
.