在angularjs

时间:2016-01-07 06:56:14

标签: javascript angularjs

我在angularjs中编写了一个回调方法。但不知何故,它没有被召集。我的代码如下。

链接功能:

link: function(scope, element, attrs) {
            scope.getContent = function(itemId) {
                getTocService.getArtData(itemId, function(data){
                    var art = data;
                    alert(art);
                });
            }
element.append("<collection collection='member.tocItem'></collection>");    
                $compile(element.contents())(scope)
            }

服务:

app.service(         “getTocService”         函数($ http,$ q){             返回({

            getArtData: getArtData
        });

        function getToc(bookIdvar) {
            var request = $http({
                method: "post",
                url: "http://10.132.241.41:8082/apdpoc/services/ApdBookService/getTOC",
                params: {
                    action: "post"
                },
                data: {
                    getTOCCriteria:{
                    bookId: bookIdvar
                    }
                }
            });
            return( request.then(handleSuccess,handleError));
        }

        function getArtData(itemId, cb) {
            var request = $http({
                method: "post",
                url: "http://10.132.241.41:8082/apdpoc/services/ApdBookService/getArticle",
                params: {
                    action: "post"
                },
                data: {
                    getArticleCriteria:{
                    articleId: itemId,
                    locale: "en_US"
                    }
                }
            });
            return(request.then(handleSuccess,handleError), cb);
        }
        function handleSuccess(response){
            return (response.data);
        }

        function handleError( response ) {

            if (
                ! angular.isObject(response.data) ||
                ! response.data.message
                ) {
                return($q.reject("An unknown error occurred."));
            }
            return($q.reject(response.data.message));
        }

    }

);

根据我对angularJs的一点知识, 回调方法应该执行

var art = data; 警报(技术);

这些台词。但控制权并没有到来。有人能让我知道这里有什么问题吗?

1 个答案:

答案 0 :(得分:1)

你应该更新

return(request.then(handleSuccess,handleError), cb);

return(request.then(cb,handleError));