【问题标题】:How to render HTML input tag in AngularJS from a HTML string returned from PHP如何从 PHP 返回的 HTML 字符串在 AngularJS 中呈现 HTML 输入标记
【发布时间】:2016-02-29 08:02:29
【问题描述】:

实际上,我正在尝试从 PHP 发送一个包含一些 HTML 元素的字符串。该 HTML 的 div 元素呈现良好,但 HTML 的所有 input 元素都没有呈现。我怎样才能做到这一点

这是我的 PHP 函数:

function testHtml(){
    $html = 'heeeeeer test <div class="abc"> abccc test....
        <input type="text" name="aaa" ng-model="rec.aaa"> 
    </div>  ';
    echo '{"result" :'.json_encode($html).'}';
}

这是我的 HTML 和 Angular 代码:

$scope.testHtml = $resource('api/item/testHtml').get(function(data){
	$scope.testhtmls =  data.result;
});
 <div class="" ng-bind-html="testhtmls">
   
 </div>

【问题讨论】:

标签: javascript php html angularjs


【解决方案1】:

在传递给ng-bind-html之前,你需要使用$sce服务:

$scope.testhtmls =  $sce.trustAsHtml(data.result);

【讨论】:

    猜你喜欢
    • 2013-07-23
    • 2019-07-22
    • 2014-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多