如何在angularjs中的ng-bind-html中使用iframe

时间:2016-02-11 11:17:43

标签: javascript angularjs iframe

这是我的控制器,我以JSON形式获取数据,这里我想绑定iframe但我无法解决,所以请帮助我,任何建议将不胜感激,谢谢提前

 angular.module('myApp.view2.controllers',[]).
        controller('mediacontroller',['$scope','$http', function($scope, $http){
            $http({
             method:"GET",
             url :"../app/media.php"
            }).then(function mySuccess(response){
                    var string = '';
                    var media_id = 0;
                    var media ;
                    var file ;
                    string = '<table border=1><thead><tr><th colspan="4">Media detail</th></tr></thead><tbody>';
                    angular.forEach(response.data, function(value, key) {

                        if(media_id===0){
                            media_id = 1;
                            string+='<tr><td class="mediatd">'+value.id+'</td><td class="mediatd">'+value.title+'</td><td class="mediatd">'+value.description+'</td></tr>';
                            string+='<tr><td class="mediatd">Category</td><td class="mediatd">Media</td><td class="mediatd">Sequence</td></tr>';

                        }else if (media_id!==value.id){
                            media_id = value.id;
                            string+='<tr><td class="mediatd">'+value.id+'</td><td class="mediatd">'+value.title+'</td><td class="mediatd">'+value.description+'</td></tr>';
                             string+='<tr><td class="mediatd">Category</td><td class="mediatd">Media</td><td class="mediatd">Sequence</td></tr>';
                        }
                        if(value.category==0){
                              media = 'image';
                              file = '<img src="http://localhost/mm2asia/img/media&news/media/'+value.media+'" style="height:100px; width:120px;" alt="">';
                        }else{
                              media = 'video';
                              file = '<iframe src="https://www.youtube.com/embed/'+value.media+'" ></iframe>';
                        }
                        string+='<tr><td>'+media+'</td><td>'+file+'</td><td>'+value.rearrange+'</td></tr>';
                        //console.log('<tr><td>'+value.id+'</td><td>'+value.title+'</td><td>'+value.description+'</td></tr>');
                    });
                    string += '</tbody></table>';
                    //console.log(string);
                    $scope.myHTML=string;
                }, function myError(response){
                    var string = '';
                    string = response.statusText;
                    $scope.myHTML=string;
            });

}]);

这是我的观点

<div ng-app="myApp">
   <div ng-controller="mediacontroller">   
      <div ng-bind-html="myHTML"></div>
   </div>
</div>

0 个答案:

没有答案