我想要 html 去哪里:
<div>{{display}}</div>
app.js
var app = angular.module('app', []);
app.controller('ctrl', function ($scope) {
$scope.contact = //get the html from contact.html
$scope.display = $scope.contact
});
联系.html
<form>
...
</form>
如何将 html 传递到 js 文件?
更新:我无法使用 ng-include,因为这是一个 SPA,因此 contact.html 所在的区域不是静态的。
最佳答案
您需要使用$sce
服务和ng-sanitize
。一旦您获得了要包含在 Controller /指令中的 HTML,请使用:
$sce.trustAsHtml($scope.htmlItem);
在您看来:
<div ng-bind-html="htmlItem"></div>
HTML 将呈现到页面上。
关于javascript - AngularJS 将 HTML 传递到作用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33437989/