search

Home  >  Q&A  >  body text

angular.js - controller获取service的值

var sdApp = angular.module("sdApp", []);

//订单;
//服务;
sdApp.service("orderService", ["$http", function(a){
    var s = {
        searchData : function(data){
            a({
                method: "post",
                url: "/?app_act=/orders/ajax_order_list&app_fmt=json",
                data: $.param(data),
                headers: {"Content-Type":"application/x-www-form-urlencoded", "x-camnpr-uid":"1000"}
            }).success(function(res){
                console.log(res);
                return res;
            });
        }
    };
    return s;
}]);

//控制;
sdApp.controller("orderSearchCtrl", ["$scope", "$http", "orderService", function(a, b, c){
    //搜索;
    a.search = function(){
        a.res = c.searchData(a.orData);
        console.log(a.res);
    };
}]);

为什么console.log出来的a.res是undefined?

世界只因有你世界只因有你2744 days ago507

reply all(1)I'll reply

  • 黄舟

    黄舟2017-05-15 16:55:46

    searchData()没有return一个返回值,默认就是undefined

    reply
    0
  • Cancelreply