【问题标题】:how to inject html page in ng-view如何在 ng-view 中注入 html 页面
【发布时间】:2015-08-26 18:30:07
【问题描述】:

我在任何教程中找到的所有代码都是注入消息字符串而不是 html 页面。 如何使用 ng-view 注入 html 页面?说 SPA 的结构是 2 个链接“添加”和“查看” Add 注入 add.html 和 View 注入 View.html

【问题讨论】:

  • 我肯定希望看到这些教程,因为路由器(ngroute 或 ui-router)上的任何文档都展示了如何使用模板和 templateUrl。你被误导了
  • 这是ng-viewng-route的官方示例:plnkr.co/edit/c4daKMuLef6lgjnSyWIE?p=preview

标签: html angularjs ng-view


【解决方案1】:

使用

ng-bind-html

您的 HTML 代码如下所示

<div ng-controller="ExampleController">
 <p ng-bind-html="myHTML"></p>
</div>

你可以通过以下方式bin html

angular.module('bindHtmlExample', ['ngSanitize'])
.controller('ExampleController', ['$scope', function($scope) {
  $scope.myHTML =
     'I am an <code>HTML</code>string with ' +
     '<a href="#">links!</a> and other <em>stuff</em>';
}]);

建议绑定html而不是htmlpage。

【讨论】:

  • 你能用例子更详尽吗?我在 angularjs 网站上找到了这个例子。就像我想在控制器中绑定我的 html 页面,而不是给出 'I am an HTMLstring with ' + 'links! 和其他 东西';我想放html文件的来源
  • "建议绑定 html 而不是 htmlpage" 我想看看你的来源是什么。
猜你喜欢
  • 1970-01-01
  • 2015-09-04
  • 1970-01-01
  • 2017-04-25
  • 1970-01-01
  • 2015-01-14
  • 1970-01-01
  • 2016-08-10
  • 2016-03-24
相关资源
最近更新 更多