热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Angular基础元素操作

2019独角兽企业重金招聘Python工程师标准Angular中主要DOM元素操作基本就两种方法:1、Renderer2、ElementRef2、ViewChi

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

Angular中主要DOM元素操作基本就两种方法:

1、Renderer2、ElementRef

2、ViewChild、ViewChildren、ContentChild、ContentChildren

class Renderer2 {get data(): {[key: string]: any}destroy(): voidcreateElement(name: string, namespace?: string|null): anycreateComment(value: string): anycreateText(value: string): anydestroyNode: ((node: any) => void)|nullappendChild(parent: any, newChild: any): voidinsertBefore(parent: any, newChild: any, refChild: any): voidremoveChild(parent: any, oldChild: any): voidselectRootElement(selectorOrNode: string|any): anyparentNode(node: any): anynextSibling(node: any): anysetAttribute(el: any, name: string, value: string, namespace?: string|null): voidremoveAttribute(el: any, name: string, namespace?: string|null): voidaddClass(el: any, name: string): voidremoveClass(el: any, name: string): voidsetStyle(el: any, style: string, value: any, flags?: RendererStyleFlags2): voidremoveStyle(el: any, style: string, flags?: RendererStyleFlags2): voidsetProperty(el: any, name: string, value: any): voidsetValue(node: any, value: string): voidlisten(target: 'window'|'document'|'body'|any, eventName: string, callback: (event: any) => boolean | void): () => void
}

class ElementRef {constructor(nativeElement: any)nativeElement: any
}

通过ElementRef查找DOM元素,如

let element = elementRef.nativeElement.querySelector('...')

通过renderer可以创建节点、元素、监听事件等等等等

 

ViewChild、ViewChildren可以从模板引用元素,ViewChildren引用的为 QueryList。

ContentChild、ContentChildren一般是在内嵌模板中用到


转:https://my.oschina.net/u/3412211/blog/1550793



推荐阅读
author-avatar
除了祝福我能怎么办_218
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有