Angularjs strongloop环回中API调用的最佳实践

Angularjs strongloop环回中API调用的最佳实践,angularjs,rest,loopbackjs,strongloop,Angularjs,Rest,Loopbackjs,Strongloop,我已经在环回中创建了可以通过rest访问的模型,我正在使用AngularJS中的rest调用,如下所示 $http.get('http://localhost:3000/api/staffs'). success(function (data, status, headers, config) { $scope.facultymembers = data; }). error(function (data, status, headers, config

我已经在环回中创建了可以通过rest访问的模型,我正在使用AngularJS中的rest调用,如下所示

 $http.get('http://localhost:3000/api/staffs').
    success(function (data, status, headers, config) {
        $scope.facultymembers = data;
    }).
    error(function (data, status, headers, config) {
     alert("Error!: "+ status );
   });

这是好的做法吗?如果不是最好的方法,请建议任何更好的方法…

是的,这是调用服务的好方法,但是如果我们的所有端点都是RESTful的,那么最好使用
$resource
然后
$http

优势 如果您使用$http,则可以获取您将调用的所有人员详细信息

 $http.get('http://localhost:3000/api/staffs').
    success(function (data, status, headers, config) {
        $scope.facultymembers = data;
    }).
    error(function (data, status, headers, config) {
     alert("Error!: "+ status );
   });
获取特定员工的详细信息

   $http.get('http://localhost:3000/api/staffs?id=' + id).
        success(function (data, status, headers, config) {
            $scope.facultymembers = data;
        }).
        error(function (data, status, headers, config) {
         alert("Error!: "+ status );
       });
但是如果你使用$resource

那就创建一个工厂

      angular.module('myApp.services').factory('staff', function($resource){
              return $resource('http://localhost:3000/api/staffs/:id'); 
        });
然后打电话询问所有员工的详细信息

staff.query(function(data){

});
通过以下方式获取特定员工的详细信息:

staff.get({id:'123'},function(data){

})

我建议使用环回角度SDK。它将帮助您自动设置与RESTAPI通信的服务。请参见我的示例:

环回就是这样做的。环回似乎没有最佳实践。他们有一个框架,但没有利用它的最佳实践。