Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.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 如何在双大括号表示法{{}的html文件中使用ng include_Javascript_Angularjs_Angularjs Ng Include - Fatal编程技术网

Javascript 如何在双大括号表示法{{}的html文件中使用ng include

Javascript 如何在双大括号表示法{{}的html文件中使用ng include,javascript,angularjs,angularjs-ng-include,Javascript,Angularjs,Angularjs Ng Include,我有以下代码: <div ng-repeat="pTabs in child.productTabs" ng-click="toggleProductTab($index)" ng-if="productTabIsActive(pTabs, $index)"> <div ng-repeat="specs in pTab.additionalSpecs"> <p>{{specs.content}}</p> <!--D

我有以下代码:

<div  ng-repeat="pTabs in child.productTabs" ng-click="toggleProductTab($index)" ng-if="productTabIsActive(pTabs, $index)">
    <div ng-repeat="specs in pTab.additionalSpecs">
        <p>{{specs.content}}</p>  <!--Displays url-->
        <div ng-include  src = {{specs.content}}></div>  <!--My attempt to display the html content-->
    </div>
</div>

{{specs.content}}

{{specs.content}
是一个html文件,包含我想在页面上使用的html。当我将其包装在
标记中时,URL在我的页面上显示为文本。如何使用ng include将html内容添加到我的页面?我试图修改语法,但到目前为止没有任何效果


非常感谢您的时间。

据我所知,您不必在angular指令中使用大括号符号。使用
ng include src=specs.content

src是ng include的一个角度指令部分,不需要花括号,您可以这样做

A)
如果html文件的字符串名称存储在范围变量或对象中

B)
如果直接在html代码中插入字符串(请注意双引号和单引号)

另外,如果您需要使用大括号在代码中插入HTML,您会注意到默认情况下,您可以在文本表示形式中转换任何HTML实体

A)
quote doble quote方法也应该适用于此

B) 如果您确实想使用大括号插入html(强烈建议您不要使用大括号,或者仅在确保html安全时使用大括号),则需要执行以下操作:

  • 将angular sanitize模块导入到项目中,并将“ngSanitize”注入到angular模块中

    • 创建一个如下所示的过滤器:
    .filter('safe',函数($sce){ 返回函数(val){ 返回$sce.trustAsHtml(val); }; })

    • 然后在你的html代码中
    {{scopeObj.var |不安全}

    • 其简单性如下所示。你就快到了

      <div  ng-repeat="pTabs in child.productTabs" ng-click="toggleProductTab($index)" ng-if="productTabIsActive(pTabs, $index)">
              <div ng-repeat="specs in pTab.additionalSpecs">
                  <p>{{specs.content}}</p>  <!--Displays url-->
                  <div ng-include  src = "{{specs.content}}"></div> 
      
                 // My ans- here I'm using  src="{{specs.content}}". Note: I'm wrapping curly braces by quotes. I assume specs.content gets required template path. eg. $scope.specs.content='templates/index.html';
              </div>
          </div>
      
      
      {{specs.content}}

      //我的ans-这里我使用src=“{{specs.content}”。注意:我用引号将大括号括起来。我假设specs.content获得所需的模板路径。例如,$scope.specs.content='templates/index.html';
      如果不起作用,请告诉我