Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 角度控制器功能未运行_Javascript_Angularjs - Fatal编程技术网

Javascript 角度控制器功能未运行

Javascript 角度控制器功能未运行,javascript,angularjs,Javascript,Angularjs,我试图让HTTP访问API,但在控制台日志中没有任何内容,所以我假设这个函数没有运行 这是我试图在Angular应用程序中重新创建的JSFIDLE,它具有正确的数据结构: 这里是controller.js .controller('GamesCtrl', function($scope, $http) { function GamesCtrl($scope, $http) { console.log("did this run"); $http(

我试图让HTTP访问API,但在控制台日志中没有任何内容,所以我假设这个函数没有运行

这是我试图在Angular应用程序中重新创建的JSFIDLE,它具有正确的数据结构:

这里是controller.js

.controller('GamesCtrl', function($scope, $http) {
    function GamesCtrl($scope, $http) {
        console.log("did this run");
        $http(
        {
            method: 'GET',
            url: 'https://www.kimonolabs.com/api/bzq274q4?apikey=JfagXh7xfxWsnWGzLAKpBIrTFwENcGY6',
            headers: {
                'authorization': 'Bearer xOZHZE4sit0Pe6VGqsOQn5jKPpA5QpG3'
            }
        }).
        success(function (data) {
            $scope.data = data['results']['collection1'];
        });
    }
})
下面是games.html

<ion-view title="Games" ng­controller="GamesCtrl">
  <ion-content>
    <ion-list>
      <ion-item ng-repeat="row in data">
        {{row['property1']['src']}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>

{{row['property1']['src']}

我甚至没有在控制台中看到来自GET的网络请求。您有两个嵌套的函数定义,第二个甚至不会被调用。请尝试以下方法:

.controller('GamesCtrl', function($scope, $http) {
    console.log("did this run");
    $http(
    {
        method: 'GET',
        url: 'https://www.kimonolabs.com/api/bzq274q4?apikey=JfagXh7xfxWsnWGzLAKpBIrTFwENcGY6',
        headers: {
            'authorization': 'Bearer xOZHZE4sit0Pe6VGqsOQn5jKPpA5QpG3'
        }
    }).
    success(function (data) {
        $scope.data = data['results']['collection1'];
    });

})

这里提供的信息不足以让我们不问20个问题就有任何想法。您没有提供关于请求状态、返回的数据结构等的信息。我只是编辑了一个问题,其中有一个指向我试图复制的JSFIDLE的链接,但我的本地项目没有返回数据。那么请求状态本身呢?在“网络”选项卡中检查它。使用错误处理程序也要确保你的url是正确的,第二件事是如果在本地它不工作,请检查它不是防火墙的问题。