Javascript 使用AngularJS将html附加到div

Javascript 使用AngularJS将html附加到div,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,如何在AngularJS控制器中传递html 这是我的列表.html: <div class="col-xs-3" ng-repeat="item in companyData"> <a ng-click="getPackageInfo({{item.iCompanyID}},'{{item.vCompanyName}}')" class="block panel padder-v bg-primary item"> <span class=

如何在AngularJS控制器中传递html

这是我的列表.html

<div class="col-xs-3" ng-repeat="item in companyData"> 
     <a ng-click="getPackageInfo({{item.iCompanyID}},'{{item.vCompanyName}}')" class="block panel padder-v bg-primary item">
      <span class="text-white block">{{item.vCompanyName}}</span>
     </a>

    <div id="packagehtml"></div>
</div>
<div id="lp" class="col-md-12 listing-div hidden"></div>
$scope.pData = [];
    $scope.getPackageInfo = function(id,name) {
        $scope.name = name;
        var summery = SubscriptionoptioncompanylistFactory.getSummary(id);
        document.getElementById("lp").classList.remove("hidden");
        $('.packages-data').html('');
        $('#loading').show();
        SubscriptionoptioncompanylistFactory.getPackageInDetail(id).
        success(function(data) {
            if(data != 0) {
                $("#lp").html(summery); // this is used to append the data
                document.getElementById("np").classList.add("hidden");
                Array.prototype.push.apply($scope.pData, data);
                $('#loading').hide();
            } else {
                document.getElementById("lp").classList.add("hidden");
                document.getElementById("np").classList.remove("hidden");
                $('#loading').hide();
            }
        });
    };

在这里,我编写了
$(“#lp”).html(Summy)
,在该div中,我必须附加来自
var summery=SubscriptionoptioncompanylistFactory.getSummary(id)的html。但这不会附加数据。在控制台中,我可以看到数据来自
摘要
变量。我该怎么办?

看看下面的修改

  • 使用角度
    ng show
    显示/隐藏元素
  • 使用数据绑定并避免类似Jquery的Dom操作

    您的代码段未显示您使用的元素:

    np, #loading  so just find them and add the `ng-show` with the proper scope variable : `npVisible , lbVisible , loadingVisible`
    
    请注意,我们使用
    summaryBinding


    希望这有帮助:)

    让我试着把它拿回来,只需打印
    {}
    ,别的什么都不要。不打印
    HTML
    请尝试:
    而不是:
    {{summaryBinding}
    和:
    $scope.summaryBinding=$sce.trustAsHtml(summy)而不是:
    $scope.summaryBinding=summy@hnn
    
        $scope.pData = [];
    $scope.getPackageInfo = function (id, name) {
        $scope.name = name;
        var summery = SubscriptionoptioncompanylistFactory.getSummary(id);
    
        $scope.lbVisible = true; //document.getElementById("lp").classList.remove("hidden");
    
        $('.packages-data').html('');
    
        $scope.loadingVisible = true; //$('#loading').show();
    
        SubscriptionoptioncompanylistFactory.getPackageInDetail(id).
                success(function (data) {
                    if (data != 0) {
    
                        $scope.summaryBinding = summery; //  $("#lp").html(summery); // this is used to append the data
    
    
                        $scope.npVisible = false; // document.getElementById("np").classList.add("hidden");
    
                        Array.prototype.push.apply($scope.pData, data);
                        $scope.loadingVisible = false; // $('#loading').hide();
                    } else {
                        $scope.lbVisible = false; //document.getElementById("lp").classList.add("hidden");
                        $scope.npVisible = false; //document.getElementById("np").classList.remove("hidden");
    
                        $scope.loadingVisible = false; // $('#loading').hide();
                    }
                });
    };
    
    np, #loading  so just find them and add the `ng-show` with the proper scope variable : `npVisible , lbVisible , loadingVisible`