Javascript-форум (https://javascript.ru/forum/)
-   Angular.js (https://javascript.ru/forum/angular/)
-   -   Почему then(...).error is not a function? (https://javascript.ru/forum/angular/67141-pochemu-then-error-not-function.html)

okuznetsov1 30.01.2017 19:43

Почему then(...).error is not a function?
 
app.js

var app = angular.module('tcpdumpApp', ['lumx']);

    app.controller('TcpdumpController', ['$scope', 'LxNotificationService', '$http', '$log', function($scope, LxNotificationService, $http, $log) {

        $scope.newGenerationCommand = '';
        $scope.tcpdumplists = [];
        $scope.parametrs = '';
        $scope.newPort = '';
        $scope.newHost = '';

    $scope.addTcpdumpTask = function() {

        $http.post('/anguler-tasks-tcpdump2/addData.php',{genCommand:$scope.newGenerationCommand, description:$scope.newDescription})
          .then(function(response) {

                    $scope.notify('success','Команда "' + response.data[0].command + '" успешно сгенерирована!');

                    $scope.tcpdumplists.push({
                            id: response.data[0].id,
                            command: response.data[0].command,
                            description: response.data[0].description,
                            completed: response.data[0].completed
                    });

                })
                .error(function(err){
                    $log.error(err);
                }); 

        };

    }]);

Coriolan161 30.01.2017 20:58

okuznetsov1,
потому что ту фигню которая в .error нужно запихать в твой then как еррор колбек, а сам .error убрать

okuznetsov1 30.01.2017 21:49

Таким образом можно поступить:

$http.post('/anguler-tasks-tcpdump2/editData.php',{id:tcpdump.id,command:tcpdump.command})
                .then(function(response) {
                    console.log(response.data);
                    $scope.notify('success','Команда "' + tcpdump.command + '" успешно изменена!');
                })
                .catch(function(e) {
                    console.log('Error: ', e);
                    throw e;
                });


Часовой пояс GMT +3, время: 17:31.