Javascript 在angularjs(ui.router)中解析时,模板中没有数据

Javascript 在angularjs(ui.router)中解析时,模板中没有数据,javascript,angularjs,Javascript,Angularjs,我没有HTML输出,但是当我console.log我的$http.get的结果时,我得到了我想要的对象。有人能解释一下如何从我的模板中的$http.get获取数据吗 .state('secure/contacts',{ url:'/secure/contacts', template:"Contacts: {{contacts | json}}", resolve:{

我没有HTML输出,但是当我
console.log
我的
$http.get的结果时,我得到了我想要的对象。有人能解释一下如何从我的模板中的
$http.get
获取数据吗

.state('secure/contacts',{
                url:'/secure/contacts',
                template:"Contacts: {{contacts  | json}}",
                resolve:{
                    contacts : function(UserService){
                        return UserService.all();
                    }
                },
                controller:function($scope,contacts){

                    $scope.contacts = contacts;


                }
            })

.service('UserService',function($http){
   return {
       get:get,
       all:all
    } ;

    function all(){
        $http.get('/api/contacts').then(function(payload){
            console.log(payload.data);
            return payload.data;
        });
    }

    function get(id){
        return $http.get('/api/user/'+id).then(function(payload){
            return payload.data;
        });
    }

});

您需要从
UserService返回承诺(
return$http.get(…)
)。所有方法:

function all() {
    return $http.get('/api/contacts').then(function(payload) {
        return payload.data;
    });
}
您的
all()
函数不返回任何内容

替换

function all(){
    $http.get('/api/contacts').then(function(payload){
        console.log(payload.data);
        return payload.data;
    });
}

function all(){
    return $http.get('/api/contacts').then(function(payload){
        console.log(payload.data);
        return payload.data;
    });
}