2016-06-09 4 views
0

컨트롤러에서 서비스로 데이터를 가져 와서 서비스별로 컨트롤러로 리턴하여 html보기로 사용하는 방법 이것은 내 서비스 파일컨트롤러에서 서비스로 데이터를 가져온 다음 컨트롤러에서 서비스로 돌아가서 html보기로 사용하기

입니다.
mymodule.service("rest",function(Restangular){ 
return { 
     save: function(tablename,data){ 
      Restangular.all(tablename).post(data).then(function(resp){ 

      }) 
     } 
     }}) 

그리고 이것은 내 컨트롤러 파일에

rest.save('custom_work',$scope.newtype) 
        toastrservice.success("New Type Added SuccessFully") 
        $scope.newtype ="" 
난 그냥 컨트롤러에 인공 호흡기 서비스에서 저장된 데이터를 얻을 원하는 HTML 페이지에 표시 할

답변

0

코드에 매우 가깝습니다. 서비스 내부의 함수를 반환하고 컨트롤러 내부에서 .then을 수행하면됩니다. 다른 코드가 맞다고 가정하면이 코드가 올바르게 작동합니다. -

mymodule.service("rest",function(Restangular){ 
return { 
    save: function(tablename,data){ 
     return Restangular.all(tablename).post(data); 
    } 
}}) 

rest.save('custom_work',$scope.newtype).then(function(response){ 
    // Use response variable for the response from service. 
    toastrservice.success("New Type Added SuccessFully") 
    $scope.newtype ="" 
}) 
관련 문제