显示在promise中$http的DOM中

display in DOM from $http from promise

本文关键字:DOM http promise 显示      更新时间:2023-09-26

好的学生已经学习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,看看如何从模板中的控制器访问数据。