search

Home  >  Q&A  >  body text

angular.js - angularJS official website phonecat example, how to get the phonelist after registering the Phone service?

I am learning AngularJS recently. In Step-11, I registered the Phone service instead of sending an http request in the controller to obtain phones/:phoneId.json. But I don’t know why Phone.query() in PhoneListCtrl can get the phonelist.

I hope someone can give me an answer.

The following is the code modification of Step-11: https://github.com/angular/angular-phonecat/compare/step-10...step-11

PHP中文网PHP中文网2794 days ago649

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