AngularJS:将范围绑定到REST iframe
我有一个表格来修改我的范围。然后使用此范围更新我网站中的另一部分。 这一部分,我现在想把它放在一个单独的(模板)文件中,并动态加载到iframe中 如果我向Iframe提供静态HTML,它就可以工作,但是在加载另一个文件作为模板时,我无法让它运行 这是我当前的代码:AngularJS:将范围绑定到REST iframe,angularjs,iframe,asynchronous,angularjs-directive,angular-http,Angularjs,Iframe,Asynchronous,Angularjs Directive,Angular Http,我有一个表格来修改我的范围。然后使用此范围更新我网站中的另一部分。 这一部分,我现在想把它放在一个单独的(模板)文件中,并动态加载到iframe中 如果我向Iframe提供静态HTML,它就可以工作,但是在加载另一个文件作为模板时,我无法让它运行 这是我当前的代码: cvFormApp.directive('cvframe', function($compile, $http, appConfig) { $http({ url: appConfig.baseUrl + 'res/te
cvFormApp.directive('cvframe', function($compile, $http, appConfig) {
$http({
url: appConfig.baseUrl + 'res/templates/classic.html',
method: 'GET'
}).then(function(response) {
tpl = response.data;
});
return function($scope, $element, tpl) {
var $body = angular.element($element[0].contentDocument.body),
template = $compile('<h1>The date in the iframe is {{date}}</h1>')($scope);
$body.append(template);
};
});
cvFormApp.directive('cvframe',function($compile,$http,appConfig){
$http({
url:appConfig.baseUrl+'res/templates/classic.html',
方法:“获取”
}).然后(功能(响应){
tpl=响应数据;
});
返回函数($scope$element,tpl){
var$body=angular.element($element[0].contentDocument.body),
template=$compile('iframe中的日期为{{date}}')($scope);
$body.append(模板);
};
});
如何将引用的classic.html插入iframe并绑定到其余代码?我不确定您想要什么。我认为在使用
$http
调用异步加载模板时,您正在处理ansync响应。您应该已经从$http
成功添加了该模板
指令
cvFormApp.directive('cvframe', function($compile, $http, appConfig) {
return function($scope, $element, tpl) {
$http({
url: appConfig.baseUrl + 'res/templates/classic.html',
method: 'GET'
}).then(function(response) {
var $body = angular.element($element[0].contentDocument.body),
template = response.data;
$body.append($compile(template)(scope)); //appended compiled element to DOM
});
};
});
太好了,行得通。但不知何故,它并不是在编译加载的内容。它留下了大量的{{variables}},而不是将其绑定到作用域。您需要使用当前作用域编译模板变量..将使其工作..这就成功了!谢谢。@nogga很高兴帮助你。。谢谢:)