首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏全栈修仙之路

    Angular ViewChild和ViewChildren

    ViewChild Angular 为我们提供 ViewChild 和 ViewChildren 装饰器来获取模板视图中匹配的元素。ViewChild 是属性装饰器,用来从模板视图中获取匹配的元素。 组件,我们需要同步更新一下 AuthFormComponent 组件,具体如下: import { Component, Output, EventEmitter, ContentChildren, ViewChild ViewChildren 与 ContentChild 装饰器类似,ViewChild 装饰器也有与之对应的 ViewChildren 装饰。 Viewchild 和 ElementRef 在 ViewChild 小节,我们使用 @ViewChild(AuthMessageComponent) 装饰器来获取 AuthMessageComponent 组件,ViewChild 装饰器除了支持 Type 类型参数外,还支持字符串参数,而字符串的值是模板引用的值。

    3.5K20发布于 2019-11-05
  • 来自专栏小鑫同学编程历险记

    【Angular教程】-内容投影u002F@ContentChildu002F@ViewChild

    @ViewChild & @ViewChildren 使用这两个装饰器来对指接子组件进行操作 使用注解在业务组件中定义子组件 @ViewChild(HelloWorldComp) helloComp

    1.2K30编辑于 2022-12-25
  • 来自专栏无所事事者爱嘲笑

    ionic2 处理android硬件返回按钮

    解决 在app.html中,添加#myNav,在app.component.ts文件通过@ViewChild('myNav')获取: <ion-nav #myNav [root]="rootPage"> </ion-nav> 在app.component.ts中: import {Component, ViewChild} from '@angular/core'; import {Platform export class MyApp { rootPage = TabsPage; backButtonPressed: boolean = false; //用于判断返回键是否触发 @ViewChild tab3Root" tabTitle="Contact" tabIcon="contacts"></ion-tab> </ion-tabs> 在tabs.ts中: import {Component, ViewChild } from "ionic-angular"; @Component({ templateUrl: 'tabs.html' }) export class TabsPage { @ViewChild

    1.6K40发布于 2018-06-20
  • 来自专栏前端布道

    Angular开发实践(七): 跨平台操作DOM及渲染器Renderer2

    通过 模板变量、@ViewChild 等方法获取DOM元素。 为了演示,先定义一个组件DemoComponent: import { AfterViewInit, Component, ElementRef, Renderer2, ViewChild } from -- DIV的id:demoDiv --> ` }) export class DemoComponent implements AfterViewInit { @ViewChild(' demoDiv') demoDiv: ElementRef; // @ViewChild通过模板变量名获取 constructor(private renderer: Renderer2) { @ViewChild @ViewChild('demoDiv') demoDiv: ElementRef; // @ViewChild通过模板变量名获取 ngAfterViewInit() {

    3.1K90发布于 2018-04-11
  • 来自专栏全栈程序员必看

    angular框架如何实现父子组件传值、非父子组件传值

    文章目录 1.理解父子组件、非父子组件 2.父组件给子组件传值- -@input 3.父组件通过@ViewChild主动获取子组件的数据和方法 4.非父子组件如何传递数据 1.理解父子组件、非父子组件 3.父组件通过@ViewChild主动获取子组件的数据和方法 在angular也提供了一个@Output修饰器来实现子组件给父组件传值,但是这个方法是较复杂的,我们使用另一种@ViewChild方法来实现 调用子组件,给子组件定义一个名称 <app-shopping #msg> </app-shopping> #号后面加一个变量名,组成模板变量 在父组件中引入viewChild: import { Component,OnInit,ViewChild } from '@angular/core'; export class NewsComponent implements OnInit{ 第二步:在子组件定义好数据 第三步:在父组件使用viewChild接收子组件数据 第四步:这时可以在父组件的ts文件或模板文件中使用子组件所有数据或方法 注意:可以在父组件通过

    2.2K20编辑于 2022-08-27
  • 来自专栏前端侠2.0

    【译】Angular中,向子组件传值的5种方式

    本文,让我们跟随 accompanying demo app  的示例来阐述下面5个技术: @Input来响应变化的值 @ViewChild来设置属性 在services中使用BehaviorSubjects ViewChild 使用ViewChild,你可以操作子组件内的属性以及方法。在动态插入组件或元素时,你可以通过子组件的类或模板引用变量的方式,来直接引用子组件,这技术就会得心应手。 要使用ViewChild,需要传入子组件的类或是模板引用变量,这样在父组件内轻易的得到属性指向子组件。 这个声明只会查询组件内第一个PriceComponent的实例: @ViewChild(PriceComponent) priceComponent; 如果你的模板中使用引用变量: <app-price-component #price></app-price-component 下面的声明能让你创建一个它的引用 @ViewChild('price') priceComponent;

    3.1K20发布于 2018-12-19
  • 来自专栏一只想做全栈的猫

    【Angular】Angula6中的组件通信

    父组件接收消息 <app-child (initEmit)="accept($event)"></app-child> accept(msg:string) { alert(msg); } 方法二 使用 ViewChild '; } 父组件使用 ViewChild 触发并接收信息 <button (click)="getInfo()">获取子组件1号的信息</button>

    {{ info }}

    import { Component, OnInit, ViewChild } from '@angular/core'; ... @ViewChild(ChildFirstComponent) private childcomponent: ChildFirstComponent; getInfo() { this.info

    3K20发布于 2019-05-26
  • 来自专栏全栈程序员必看

    angular父子组件传值

    angular父子组件传值 父组件到子组件 1.父组件传递数据 2.子组件接受数据 子组件到父组件 1.父组件根据ViewChild获取子组件实例 2.子组件通过广播的形式,向子组件发送数据 子组件操作 msg}}

    getParentFunc(){ this.run(); console.log(this.home.title) } 子组件到父组件 1.父组件根据ViewChild button (click)="getChildMsg()">获取子msg</button> <button (click)="getChildFunc()">获取子方法</button> //父组件引用ViewChild import { HttpClient,HttpHeaders} from '@angular/common/http' //根据ViewChild获取子组件实例 @ViewChild('top

    1.2K10编辑于 2022-08-27
  • 来自专栏奔跑的蛙牛技术博客

    ElementRef & TemplateRef & ViewContainerRef

    今天在做ng项目,看着前人的代码有 viewChild() 等关键字。

    ` }) export class AppComponent(){ @ViewChild('greet') greetDiv: ElementRef 不能直接实例化抽象类应该实例抽象化类的子类,每个实例都具有createEmbeddedView方法 ViewContainerRef import { Component, TemplateRef, ViewChild template </template> `, }) export class AppComponent { name: string = 'Semlinker'; @ViewChild ('tpl') tplRef: TemplateRef<any>; @ViewChild('tpl', { read: ViewContainerRef }) tplVcRef: ViewContainerRef

    1.5K20发布于 2018-09-05
  • 来自专栏全栈修仙之路

    Angular 动态创建组件

    ng-template #alertContainer></ng-template> ` }) export class AppComponent { } 在 AppComponent 组件中,我们可以通过 ViewChild 根据以上需求,更新后的代码如下: import { Component, ViewChild, ViewContainerRef } from '@angular/core'; @Component( template: ` <ng-template #alertContainer></ng-template> ` }) export class AppComponent { @ViewChild import { Component, ViewChild, ViewContainerRef } from '@angular/core'; @Component({ selector: 'my-app click)="createComponent('danger')">Create danger alert</button> ` }) export class AppComponent { @ViewChild

    5K10发布于 2019-11-05
  • 来自专栏Angular&服务

    angular获取dom元素

    方式一: ViewChild

    @ViewChild('box') box: ElementRef; constructor(){ // 不能放在构造函数里面这个时候构造函数中还没有视图没法获取到

    4.9K50发布于 2019-05-15
  • 来自专栏随想

    Seam Carving demo

    | null = imgRef.current; const canvas: HTMLCanvasElement | null = canvasRef.current; Angular:通过ViewChild #imgRef id='myImg' [src]="imageSrc" alt="Original" /> <canvas #canvasRef id='myCanvas'> </canvas> @ViewChild ('imgRef', { static: false }) imgRef: ElementRef; @ViewChild('canvasRef', { static: false }) canvasRef isResizing: boolean = false; imageSrc: SafeUrl = ""; SelectImg: boolean = false; @ViewChild ('imgRef', { static: false }) imgRef: ElementRef; @ViewChild('canvasRef', { static: false })

    2.6K30发布于 2021-05-27
  • 来自专栏农历七月廿一

    angular知识点梳理第三篇-组件

    在父组件引入子组件的地方添加节点值 【parent.component.html】 第二步:在子组件中声明一些需要传递的变量 【children.component.ts】 第三步:在父组件的ts文件中引入viewchild 子组件传值(函数)给父组件 方案一 通过viewchild进行节点获取 第一步:在父组件引入子组件的地方添加节点值 【parent.component.html】 <! 模块 【parent.component.ts】 // 引入angular核心模块的viewchild模块 import { Component, OnInit,ViewChild } from '@angular /parent.component.less'] }) export class ParentComponent implements OnInit { //使用viewchild装饰器进行节点值的获取 @ViewChild('childrenNode') children:any constructor() { } ngOnInit(): void { } //声明一个需要传递给子组件的函数

    3.1K10编辑于 2022-05-09
  • 来自专栏全栈修仙之路

    Angular ElementRef 简介

    其实在 Angular 框架内部已经为我们提供了解决方案,它为我们提供了内置的装饰器,如 @ContentChild、 @ContentChildren、@ViewChild、@ViewChildren 具体使用示例如下: import { Component, ElementRef, ViewChild, AfterViewInit } from '@angular/core'; @Component #greet>Hello {{ name }}

    `, }) export class AppComponent { name: string = 'Semlinker'; @ViewChild 最后我们来看一下,最终优化后的代码: import { Component, ElementRef, ViewChild, AfterViewInit, Renderer2 } from '@angular #greet>Hello {{ name }}
    `, }) export class AppComponent { name: string = 'Semlinker'; @ViewChild

  • 2.1K60发布于 2019-11-06
  • 来自专栏ionic3+

    【组件篇】ionic3分组索引及锚点滚动列表

    } .modal.show { opacity: 1; } } index-list.ts: import { Component, ElementRef, ViewChild false; @ContentChildren(IndexGroupComponent) _listOfIndexSection: QueryList<IndexGroupComponent>; @ViewChild ng-content></ng-content> </ion-item-group> index-group.scss不需要 index-group.ts: import { Component, Input, ViewChild class IndexGroupComponent { @Input() index: string = 'A'; @Input() headColor: string = 'light'; @ViewChild

    2K20发布于 2018-08-20
  • 来自专栏Angular学习规划

    Angular核心-父子间组件传递数据-重难点

    <app-myc01 #c1></app-myc01>
    <app-myc02 #c2 ></app-myc02> 在ts文件里: @ViewChild ('c0',{static:true})//这个c0表示组件c1 private c0: any;//这个c0是自己起的名字,与组件c0绑定 @ViewChild('c1',{static:true }) private c1: any; 提示:ViewChild装饰器用于将子组件识别符与某个属性关联起来,第一个参数必须是已经存在的子组件识别符(不带#),第二个参数static指定该组件是否为“ 静态组件”—不会有时有时无的组件(比如ngIf,ngFor) 注意: 通过“ViewChild”-视图组件方式,父组件可以获得任意子组件中的数据,在一定程度上违反了“最少知识法则” 我的博客即将同步至腾讯云开发者社区

    1.7K20编辑于 2022-06-28
  • 来自专栏学海无涯

    Android开发之项目经验分享

    = (ViewGroup) view; for (int i = 0; i < vp.getChildCount(); i++) { View viewchild = vp.getChildAt(i); allchildren.add(viewchild); allchildren.addAll(getAllChildViews (viewchild)); } } return allchildren; } public void check(List<View> list)

    94150发布于 2018-05-03
  • 来自专栏全栈修仙之路

    Angular DOM 抽象概述

    装饰器获取匹配的 ElementRef 实例 import { Component, ElementRef, ViewChild, AfterViewInit } from "@angular/core

    Semlinker

    ` }) export class HelloWorldComponent implements AfterViewInit { @ViewChild ("tpl") tplRef: TemplateRef<HTMLElement>; @ViewChild("tpl", { read: ViewContainerRef }) tplVcRef
    ` }) export class AppComponent implements AfterContentInit { @ViewChild 实际工作中,还需要利用 ViewChild、ViewChildren、ContentChild 和 ContentChildren 装饰器,或者基于 Angular 依赖注入特性,通过构造注入的方式,获取相关的对象

    4.7K30发布于 2019-11-05
  • 来自专栏前端之攻略

    ionic2-页面的生命周期 原

    /contact/contact'; import {Tabs} from 'ionic-angular'; import {Injectable,ViewChild} from '@angular/core '; @Component({ templateUrl: 'build/pages/tabs/tabs.html' }) export class TabsPage { @ViewChild(

    59320发布于 2019-04-04
  • 来自专栏前端侠2.0

    ng6的ng-template的一个用法 原

    组件模板: <ng-template #tpl>      

    i am in tpl {{name }}
    </ng-template> ts 组件内: @ViewChild ('tpl') tpl: TemplateRef<any>; @ViewChild('tpl', {read: ViewContainerRef}) vc: ViewContainerRef;  //

    1.8K30发布于 2018-09-21
  • 第 2 页第 3 页第 4 页
    点击加载更多
    领券