使用Angular在ionic1视图中的http.get请求中显示在变量中捕获的HTML

时间:2017-02-09 10:56:00

标签: angularjs ajax http ionic-framework

当tryintg在离子视图中使用Angular绘制在HTTP请求中捕获的HTML页面时,我遇到了问题。

我的控制器代码:

app.controller('MiNegocioCtrl', function ($scope, ajax, $sce) {
    ajax.sendApiRequest({}, "GET", url, true).then(function (response) {
        $scope.data = response.data;

        console.log(response.data);
        var negocio = angular.element("#negocio");
        negocio.html(response.data);
    }, function (error) {
        _showPopUp('error', 'error');

    });
})

我的观看代码:

<ion-view title="Negocio" id="page10">
    <ion-content>
        <div id="negocio" style="width: 100%;height: 100%"></div>
    </ion-content>
</ion-view>

1 个答案:

答案 0 :(得分:0)

我希望能帮助您解决以下问题:

// In your controller, inject the $sce service, and mark the HTML as "trusted":
.controller('MiNegocioCtrl', function($scope, $http, $sce) {
  $scope.data = "";

// make request with service $http
  $http.get(url).then(function (response) {
    $scope.data = $sce.trustAsHtml(response.data);
  });

})

你的观点。使用指令 ng-bind-html

<ion-view title="Negocio" id="page10">

  <ion-content>
      <div ng-bind-html="data" style="width: 100%;height: 100%"></div>
  </ion-content>

</ion-view>