$ http内部的promise成功回调没有执行Angularjs

时间:2016-09-07 08:11:06

标签: javascript angularjs

所以我有以下代码:

$scope.remove = function( smallGroupTypeId, smallGroupTypeIndex, $event ) {
    $http({
        method: "POST",
        url: BASE_URL + "/small-group-type/" + smallGroupTypeId + "/delete",
        headers: { 
            "Content-Type" : "application/x-www-form-urlencoded" 
        }
    })
    .success( function( data ) {
        if ( data.success == true ) {
            toastr.success('Message', data.message);
            $scope.smallGroupTypes.splice( smallGroupTypeIndex, 1 );
            var tr = angular.element( $event.currentTarget.closest( "tr" ) ) ;
            tr.remove();
            $scope.search()
        } else {
            toastr.success('Message', data.message);
        }
    });
};

这段代码删除了一个项目然后成功函数它应该调用search()函数,里面是另一个$ http调用。但是,我进入了成功函数,但$ scope.search()从未执行过。

这是我的$ scope.search():

    $scope.search = function( otherParams, $event ) {
    SearchFactory.search( $scope.searchCallback, otherParams, $event );
};

这是我的SearchFactory.search()代码:

factory.search = function ( callback, otherParams, $event ) {

    $rootScope.otherParams = angular.merge({}, $rootScope.otherParams , otherParams);

    if (typeof $rootScope.otherParams == "undefined") {
        $rootScope.otherParams = {};
    }

    if (typeof otherParams != "undefined" && typeof otherParams.sort != "undefined") {
        factory.toggleSortingDirection( $event );
    } else {
        factory.pageActive( $event );
    }

    var params = angular.extend( {}, $( "form" ).serializeObject(), $rootScope.otherParams );

    $http({
        method: "GET",
        url: URI,
        params:  params,
        headers: {
            'Content-Type': 'application/json'
        },
    }).then( function( response ) {
        callback(angular.fromJson(response.data.items), angular.fromJson(response.data.data));
    });
};

为什么会这样?

感谢。

0 个答案:

没有答案