我有一些模板,我正在使用角度$compile填充数据库中的一些数据。然后,我必须将其插入iframe中以将其显示给用户,然后将其保存在数据库中。
我的问题是,当我将模板移出范围时,通过绑定内容放置在其中的数据消失了。我必须做什么来保留绑定的数据?
我尝试创建一个新范围并使用现有范围,但在这两种情况下都失败了。
这是我编译内容的地方:
//Method is called by the user
$scope.mountTemplate = function() {
//Load the template the user chose before
TemplateLoader.getTemplate($scope.modelTemplate.template + '.html').then(function(responseTemplate) {
//Load the template the user chose before, here i just read the html from a file
loadRegisters(url, $scope.formContentData.selected, append)
.then(function(response) {
$scope.itensTemplate = response.map(function(elem) { return configRegisters(elem); });
var compiledHTML = $compile(responseTemplate)($scope);
//Here the data appears
$('#divVisualizer').append(compiledHTML);
$timeout(function() {
//At this point, when i log it the ng-repeat and other binded data disappears
console.log('compiledHTML', compiledHTML);
}, 1000);
//At this point, when i place it inside the iframe the ng-repeat and other binded data disappears
$scope.trustedHTML = compiledHTML;
}, function(response) {
console.log('response', response);
});
}, function(response) {
console.log(response);
});
}
我应该怎么做才能保留绑定的数据?此外,我需要编译的响应是一个字符串,它作为一个对象返回。如何转换它?
编辑
为了澄清我的应用程序的作用:我正在构建一个时事通讯构建器,用户在其中从数据库中选择一些寄存器和一个模板来填充这些寄存器,然后将其保存在数据库中,以便稍后通过电子邮件发送。
我已经设法解决了使用服务和指令的问题,并使用 defer 来帮助加载和填充数据