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
巴扎黑2017-05-15 16:55:45
The reason is this sentence:
javascript
return $resource('phones/:phoneId.json', {}, { query: {method:'GET', params:{phoneId:'phones'}, isArray:true} });
phoneService
返回了一个 $resource
,这个 $resource
注册了一个 action 叫 query
,该方法访问的路径、HTTP 方法、参数、返回数据类型都在上述代码里,最终会调用底层的 $http
The service initiates a request to get the data.