Angularjs 离子-单击按钮时填充离子列表

Angularjs 离子-单击按钮时填充离子列表,angularjs,ionic,Angularjs,Ionic,我有一份离子清单。我想在单击按钮时将数据绑定到列表 $scope.searchY = function(){$scope.youtubeParam = { key: 'myKey', type: 'video', maxResults: '10', part: 'id,snippet', q: $scope.searchKey , order: 'date',}; $http.get('https://www.googleapis.com/youtube/v3/se

我有一份离子清单。我想在单击按钮时将数据绑定到列表

 $scope.searchY = function(){$scope.youtubeParam = {
  key: 'myKey',
  type: 'video',
  maxResults: '10',
  part: 'id,snippet',
  q:  $scope.searchKey ,
  order: 'date',};

$http.get('https://www.googleapis.com/youtube/v3/search', {params:$scope.youtubeParam}).success(function(response){
$scope.myVideos = response.items;
  angular.forEach(response.items, function(child){
    console.log (child);
  });   
});
我在搜索文本框中放置了一个事件,如下所示

 <ion-content>
    <div>
        <label class="item item-input">
            <i class="icon ion-search placeholder-icon"></i>
            <input type="search" placeholder="Search" ng-enter="searchY()" ng-model="searchKey">
        </label>
    </div>
    <!--<div class="embed-responsive embed-responsive-16by9"><youtube-video  video-id="theBestVideo"></youtube-video></div>-->
    <div data-ng-controller="AppCtrl" class="list card" ng-repeat="video in myVideos">
        <div class="item item-text-wrap">
            <h2>{{video.snippet.title}}</h2>
            <p>{{video.snippet.publishedAt | limitTo: 10}}</p>
        </div>
        <div class="item item-image">
            <div class="embed-responsive embed-responsive-16by9"><youtube-video class="embed-responsive-item" video-id="video.id.videoId" player-vars="playerVars"></youtube-video></div>
        </div>
        <div class="item item-divider">
            <button class="button button-outline button-block button-positive">
                Share this Video
            </button>
        </div>
    </div>
</ion-content>

当我进行搜索时,我可以看到返回的结果,$scope.myVideos变量不是空的。但它并没有和列表卡绑定在一起。请问我做错了什么。好几天了。如果我直接调用该函数而不进行搜索,它就会工作。谢谢

每个控制器都会创建一个新的作用域,因此您的搜索框和视频列表会查看不同的作用域。当您从搜索框正在查看的范围中修改myVideos时,更改不会反映在AppCtrl正在查看的范围中


尝试将ng controller=AppCtrl移动到ion内容标记,然后在搜索返回时,可以修改正确的范围,更改应反映在ion列表中。

您好,abhishek,非常感谢您的回复。我确实想更新$scope.myVidoes变量。当我使用搜索框进行搜索时。但是它抛出的错误$apply已经在进行中。因此,我使用了两个不同的列表卡,设置了另一个变量,同时将另一个变量置零。有没有更新$cope变量的方法?如果这对其他人有帮助,我只需将新的$scope.myVidoes更新放在超时函数中:$timeoutfunction{$scope.myVideos=response.items;}