[英]How to create a Javascript Node in Angular.JS
Simple question, I essentially want to do something like the following, but in "angularness" 简单的问题,我本质上想做类似以下的事情,但是要“成角度”
var p = document.createElement("p");
document.body.appendChild(p);
I have the appendChild part, I just don't know how to create an element that is of type Node and didn't find anything on it. 我有appendChild部分,我只是不知道如何创建Node类型的元素,并且在该元素上找不到任何内容。 I know you can create an element using
angular.element("<div></div>")
however the problem with that is that is not of type Node and the appendChild method will not accept it. 我知道您可以使用
angular.element("<div></div>")
创建一个元素,但是存在的问题是它不是Node类型,并且appendChild方法将不接受它。
With Angular's jqlite you would do the similar thing as with jQuery. 使用Angular的jqlite,您将执行与jQuery类似的操作。
var p = angular.element("<p>")[0]; // now it's node
document.body.appendChild(p);
And conversely 相反
var p = document.createElement("p");
angular.element(document.body).append(angular.element(p));
If you've got p
from the outside and don't know exactly if it is DOM or jqLite element, use angular.element
wrapper for it anyway (again, as you would do with jQuery). 如果您从外部获得
p
,并且不确切知道它是DOM还是jqLite元素,则无论如何angular.element
使用angular.element
包装器(同样,与jQuery一样)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.