首页 > 解决方案 > 在自定义工厂服务中使用 $http

问题描述

我的服务有两个功能。一个只是返回一个可以正常工作并完美显示在视图上的字符串。但是另一个函数对后端进行 $http 调用。$http 调用工作正常,但无法将结果拉到控制器

(function(){

var videoStoreApp = angular.module('videoStoreApp', ['ui.router']);


videoStoreApp.factory('videoListService', function($http, $rootScope){

    var myService = {};   

    myService.getData = function()
    {           

        return $http({
           method: 'GET',
           url: 'app/services/getDvd.php'
        }).then(function(data){                          
             var returnObj = {
                 complete:true,
                 data: data.data
             };
             return returnObj;
        });       
    };   

    myService.getSum =  function()
    {
        return 'services test';
    };

    return myService;
});
})();

这就是我从控制器调用服务的方式......

angular.module('videoStoreApp').component('videoList', {

    templateUrl: 'app/views/videoList.html',
    controller: function videoListFunction($http,$scope,videoListService){

    $scope.test3 = videoListService.getSum();
    $scope.dvd =  videoListService.getData();
 };
}
});

有人可以帮忙吗。这是我第一次在 stack over flow 上发布问题

标签: angularjs

解决方案


这是标记

            <ul>
                <li ng-repeat="dvd in $ctrl.dvd">
                    <a href="" ng-click="selectMovie(dvd.film_id)">{{dvd.title}}</a>                        
                </li>
            </ul>   

推荐阅读