Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.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
Angularjs ng将html值绑定到其他html标记_Angularjs_Ng Bind Html_Ng Bind - Fatal编程技术网

Angularjs ng将html值绑定到其他html标记

Angularjs ng将html值绑定到其他html标记,angularjs,ng-bind-html,ng-bind,Angularjs,Ng Bind Html,Ng Bind,我想从NgBindHTML获取数据,并将其绑定到其他一些html标记。尽管我可以直接使用NgBindHTML。但是有没有其他方法可以将绑定的html用于其他html标记 JS: $scope.left = '<span>Hello World</span><strong>New Testing<strong><br/>h1>Testing</h1>'; <div ng-bind-html="left" ng-

我想从NgBindHTML获取数据,并将其绑定到其他一些html标记。尽管我可以直接使用NgBindHTML。但是有没有其他方法可以将绑定的html用于其他html标记

JS

 $scope.left = '<span>Hello World</span><strong>New Testing<strong><br/>h1>Testing</h1>';
<div ng-bind-html="left" ng-model="GetValues"></div>

<span>{{GetValues}}</span>
$scope.left='Hello World新测试
h1>测试';
HTML

 $scope.left = '<span>Hello World</span><strong>New Testing<strong><br/>h1>Testing</h1>';
<div ng-bind-html="left" ng-model="GetValues"></div>

<span>{{GetValues}}</span>

{{GetValues}}

使用
trustAsHtml
将字符串编译成Dom

$scope.trustAsHtml = function(html){
   return $sce.trustAsHtml(html);
}
现在在html中调用函数

<div ng-bind-html="trustAsHtml(left)" ng-model="GetValues"></div>

角度模块(“应用程序”,[]) .controller(“ctrl”,函数($scope,$sce){ $scope.left='Hello World新测试
测试'; $scope.trustAsHtml=函数(html){ 返回$sce.trustAsHtml(html); } })

{{GetValues}}
方法1:使用 html


指示
var-app=angular.module('myApp',[]);
应用控制器('ctrlMain',功能($scope){
$scope.bindMe={id:1,myvar:“test”};
});
app.directive('myDirective',函数($compile){
返回{
限制:“A”,
范围:{
varToBind:'=myDirective'
},
链接:功能(范围、elm、属性){
outerList='Hello World新测试
h1>测试'; outerList=$compile(outerList)(范围); 榆树替换(外层); } } });
方法2:使用 您可以直接包含一个html文件:)

//您的DOM字符串代码应该在myfile.htm文件中

我认为OP要求
任何其他绑定到html字符串的指令
<div ng-include="'myFile.htm'"></div>//your DOM string code should be in myfile.htm file