Home  >  Q&A  >  body text

angular.js - angularJS官网phonecat例子,注册了Phone服务之后怎么获取到phonelist?

最近在学习AngularJS,在Step-11中,注册了Phone服务代替控制器中发http请求获取phones/:phoneId.json。但是不知道PhoneListCtrl里面为什么Phone.query()就可以获取到phonelist。

希望有高手能够解答一下。

下面是Step-11的代码修改的地方: https://github.com/angular/angular-phonecat/compare/step-10...step-11

PHP中文网PHP中文网2649 days ago538

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-05-15 16:55:45

    The reason is this sentence:

    javascriptreturn $resource('phones/:phoneId.json', {}, {
        query: {method:'GET', params:{phoneId:'phones'}, isArray:true}
    });
    

    phoneService 返回了一个 $resource,这个 $resource 注册了一个 actionquery,该方法访问的路径、HTTP 方法、参数、返回数据类型都在上述代码里,最终会调用底层的 $http The service initiates a request to get the data.

    reply
    0
  • Cancelreply