Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ng绑定html在我的上下文中不起作用_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript ng绑定html在我的上下文中不起作用

Javascript ng绑定html在我的上下文中不起作用,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我正在使用ngBindHtml指令在AngularJS中追加HTML。它正在追加一些未正确添加到div中的区域标记属性,但与预期不同 因此区域标记中的onclick事件不起作用。首先,它不是附加在html中,而是在我正在使用的jQuery.html()中,它工作得很好。 我想用角度的方法得到答案 HTML 控制器 $scope.editor=“ ”; 输出 在输出缺失区域中,单击标记属性onclick=“document.images.shirtguidemeasure.src和样

我正在使用
ngBindHtml
指令在AngularJS中追加HTML。它正在追加一些未正确添加到
div
中的区域标记属性,但与预期不同

因此区域标记中的
onclick
事件不起作用。首先,它不是附加在html中,而是在我正在使用的jQuery
.html()
中,它工作得很好。 我想用角度的方法得到答案

HTML

控制器
$scope.editor=“

”;
输出



在输出缺失区域中,单击标记属性
onclick=“document.images.shirtguidemeasure.src
和样式。

ng bind html
正在使用
$sanitize
服务进行清理。作为其中的一部分,从输出中删除一些不安全的令牌。在Angular的旧版本中,您可以使用
ng-bing-html-unsafe

<div ng-bind-html-unsafe="editor"></div>

我认为你把单引号和双引号混用了, 加上多行的HTML应该被引用:

$scope.editor =  
  '<p>'+
  '<h1 style="color: red;">MY HEADER</h1>'+
  '</p>';
$scope.editor=
“”+
“我的头”+
“

”;
你能发一把小提琴吗?@Mast-谢谢你的编辑,我批准了
<div ng-bind-html="editor" class="ng-binding">
<p>
<img alt="how to measure" src="http://www.jcpenney.com/dotcom/images/2013_09_SHIRT_TAB1_HOW_TO_MEASURE.jpg" usemap="#imgmap201310911202">
<map>
<area alt="how to measure" coords="5,4,153,31" shape="rectangle" title="how to measure">
<area alt="classic" coords="157,4,306,31" shape="rectangle" title="classic">
<area alt="slim" coords="310,3,459,31" shape="rectangle" title="slim">
<area alt="big and tall" coords="464,3,617,31" shape="rectangle" title="big and tall">
</map>
</p>
</div>
<div ng-bind-html-unsafe="editor"></div>
angular.module('mySceApp', ['ngSanitize'])
    .controller('AppController', function($scope, $sce) {
            $scope.editor = $sce.trustAsHtml('YOUR UNSAFE HTML GOES HERE');
        }
    );
$scope.editor =  
  '<p>'+
  '<h1 style="color: red;">MY HEADER</h1>'+
  '</p>';