简体   繁体   English

AngularJS:如何在对象中创建对象以调用后续的HTTP调用

[英]AngularJS : how to make object in objects to call subsequent http calls

I am a completely angular newbee, and I have a question about angular ng-repeat tags. 我是完全有角度的新手,并且对角度ng-repeat标签有疑问。

Here I have a list of devices and it is about to iterate each device in the html. 在这里,我有一个设备列表,它将要遍历html中的每个设备。

The question is, if each device will start to call a separate api, for example, like /devices/:device_id/get_some_thing_else using the given device_id from each device. 问题是,每个设备是否会开始使用每个设备的给定device_id来调用单独的api,例如/ devices /:device_id / get_some_thing_else。 How do i construct my angular page with which ng tag ? 如何使用ng标签构建我的角度页面?

I want the page to display a list of devices first before having each device to call a separate API. 我希望页面先显示设备列表,然后让每个设备调用单独的API。

The ng-repeat does not actually make any API calls. ng-repeat实际上不会进行任何API调用。 It just binds to an array 它只是绑定到一个数组

Say for example you had this variable in your JS file 假设您在JS文件中有此变量

$scope.devices = [{name: "device One"}, {name: "device Two"}, {name: "device Three"}];

then in your HTML you had 然后在您的HTML中

<div ng-repeat="device in devices">
<h1>{{device.name}}</h1>
</div>

when the page was rendered it would show 页面呈现时会显示

device One
device Two
device Three

where each line was wrapped in an H1 tag and also in a DIV tag 每行都包裹在H1标签和DIV标签中

You are responsible in your javascript file for specifying how the data gets into $scope.devices, usually through a factory. 您有责任在JavaScript文件中指定数据通常通过工厂进入$ scope.devices的方式。

Whenever the data in $scope.devices changes so will the corresponding HTML. 每当$ scope.devices中的数据更改时,相应的HTML也会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 确保AngularJS中后续HTTP ajax调用的正确顺序 - Ensure the proper order of subsequent HTTP ajax calls in AngularJS 如何通过链接AngularJS中的http调用来构建对象数组? - How to build an object array by chaining http calls in AngularJS? 循环AngularJS $ http调用 - TypeError:object不是函数 - Looping AngularJS $http calls - TypeError: object is not a function 不要在随后的按钮点击时调用 http - Don't make http call on subsequent button clicks 如何将 ajax 调用结果传递给后续 ajax 调用 - How to pass ajax call result to subsequent ajax calls 用户刷新页面时如何进行angularjs $ http POST调用? - How to make angularjs $http POST call when user refresh a page? 如何在服务中进行http调用但得到控制器响应? AngularJS - How to make http call in service but get response by the controller? AngularJS RxJS 5 Observable和Angular2 http:调用ajax一次,保存结果,随后的ajax调用使用缓存结果 - RxJS 5 Observable and Angular2 http: Call ajax once, save the result, and subsequent ajax calls use cached result 成功拨打电话后如何进行后续mongo通话 - How to make subsequent mongo call after successful call 如何对第一个axios调用的数组结果进行后续axios调用? - How to make subsequent axios call for the array result of the first axios call?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM