angular.element replaceWith 不起作用 [英] angular.element replaceWith not working

查看:25
本文介绍了angular.element replaceWith 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要替换的元素,并且 html 文本是可变的 h第一次调用这个功能完美.但是第二次调用没有.

I have an element to replace and the html text is in varaiable h The first call to this works perfectly. But the second call does not.

var newElement;
var h="<div>a</div>";
newElement = angular.element(h);
$compile(newElement[0])($scope);        
angular.element($element[0]).replaceWith(newElement[0]);

推荐答案

我认为这里的错误是你已经编译了 html 模板,但你还没有使用它.

I think the mistake here is you have compiled the html template but u havent used it .

var newElement;
var h="<div>a</div>";
newElement = angular.element(h);

angular.element($element[0]).replaceWith($compile(newElement[0])($scope));

希望这个解决方案有效

这篇关于angular.element replaceWith 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆