显示在promise中$http的DOM中
display in DOM from $http from promise
好的学生已经学习js大约8周了,正在做一个最终的项目,不知道如何根据我的请求显示到DOM中。我需要将callerData与匹配项一起显示到dom中。。。我做错了什么?不要炸毁我的API密钥,否则我将不得不得到另一个。
app.controller('ListController', ['$scope', '$window', '$http', 'LeagueService', function($scope, $window, $http, LeagueService) {
//$scope.interests = LeagueService.getInterests();
$scope.searchSummoner = function () {
LeagueService.summonerByName($scope.summonerText).then(function(responseData){
console.log(responseData);
//$scope.summonerObject = responseData.data['huriey'].id;
let summonerId = responseData.data[$scope.summonerText].id;
// debugger
// make your second api call
// &seasons=SEASON2016
return $http({
method: 'GET',
url:``
});
}).then(function (summonerData) {
// angular.copy(response.data.leagues, summonerCache);
// return response;
console.log(summonerData);
$scope.searchSummoner = function (summoner) {
$window.open(`${summoner.data}`);
};
});
您的问题是,应该只在函数调用后使用then
。您可以在函数定义之后添加它。你必须按以下步骤做。那么它就起作用了。
定义您的功能
$scope.searchSummoner = function () { return $http(...)};
调用您的函数,然后您就可以使用then
$scope.searchSummoner().then(function (summonerData) {
...
});
使用angular,可以通过绑定进行显示。下面是一个绑定的简单示例:
<input type="text" value="model.someProperty"/>
或者,你可以这样做:
<span>{{ model.someProperty }}</span>
我建议你花点时间阅读angular,看看如何从模板中的控制器访问数据。
相关文章:
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 是否有任何snippet或jQuery插件可以列出easylist.txt模式匹配的DOM中的所有元素
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- Meteor如何接收HTTP请求
- 如何在DOM元素上按类型构建此函数
- Windows形成web浏览器控件和Javascript更改的DOM
- Datatables:通过DOM数据源中的名称引用列
- 在DOM中查找一个模式并替换它's的内容使用jquery
- DOM事件通过JSON转换为java
- 显示在promise中$http的DOM中
- Nodejs向http服务器发送命令以突出显示或着色DOM元素
- 如何使用 ng 无限滚动并在 http.jsonp 完成后更新另一个 DOM 元素
- 在 AngularJS 中成功的 http 请求上创建一个 DOM 元素
- AngularJS:$http请求问题-没有为jQuery函数调用更新DOM
- 在http和https之间共享dom存储
- 将整个DOM(页面)替换为AngularJS中$http的响应
- Boost Asio HTTP服务器无法处理XML DOM
- DOM不更新$http POST请求与MEAN堆栈
- Firefox插件获取了发出HTTP请求的DOM窗口
- 如何在一个很长的HTTP请求之后更新DOM,而不用在Angular中使用$scope