ibeautiful
此解决方案不使用硬编码模板,您可以编译嵌入在API响应中的Angular表达式。步骤1. 安装此指令:https://github.com/incuna/angular-bind-html-compile步骤2.在模块中包含指令。angular.module("app", ["angular-bind-html-compile"])步骤3.在模板中使用该指令:
{ content: "Dear {{letter.user.name}}," }]}HTML输出=
Dear John,
'use strict';
var module = angular.module('angular-bind-html-compile', []);
module.directive('bindHtmlCompile', ['$compile', function ($compile) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
scope.$watch(function () {
return scope.$eval(attrs.bindHtmlCompile);
}, function (value) {
element.html(value);
$compile(element.contents())(scope);
});
}
};
}]);}());