For example we have a component:

<Card ></Card>

And a driective:

<Card highlighted></Card>

We want to get the driective instant inside the component code, we can use @ViewChild:

@ViewChild(CardComponennt, {read: HighlightedDirective}) highlighted: HighlightedDirective

Then we can access the instant in ngAfterViewInited lifecycle hook.

-----

Another way to access driective is inside component template. we need to use 'exportAs' from  the directive:

@Directive({
name: 'highlighted',
exportAs: 'hl'
}) ... toggle () {...}

Inside the template, we can get it from the template reference:

<Card highlighted #hlref="hl"></Card>

<button (click)="hlref.toggle()"></button>

[Angular] @ViewChild read custom directive and exportAs的更多相关文章

  1. Angular自定义指令(directive)

    angular自定义指令,意我们可以通过angula自己定义指令,来实现我们的特殊要求,为所欲为,一支穿云箭,千军万马来相见 多少年的老规矩了,先看代码: <!DOCTYPE html> ...

  2. angular的GitHub Repository Directive Example学习

    angular的GitHub Repository Directive Example学习 <!DOCTYPE html> <html ng-app="myApp" ...

  3. angular自定义指令-directive

    Directive究竟是个怎么样的一个东西呢?我个人的理解是这样的:将一段html.js封装在一起,形成一个可复用的独立个体,具体特定的功能.下面我们来详细解读一下Directive的一般性用法. v ...

  4. [Angular] Custom directive Form validator

    Create a directive to check no special characters allowed: import {Directive, forwardRef} from '@ang ...

  5. Angular之 Scope和 Directive

    ---------------------------Scope-------------------------------- https://docs.angularjs.org/guide/sc ...

  6. [Angular] Create a custom validator for reactive forms in Angular

    Also check: directive for form validation User input validation is a core part of creating proper HT ...

  7. Angular 学习笔记 (Custom Accessor + Mat FormField + Custom select)

    custom form control 之前就写过了,这里简单写一下. 创建一个组件实现 ControlValueAccessor 接口 @Component({ providers: [ { pro ...

  8. -_-#【Angular】自定义指令directive

    AngularJS学习笔记 <!DOCTYPE html> <html ng-app="Demo"> <head> <meta chars ...

  9. angular ViewChild ContentChild 系列的查询参数

    官方说明 官方文档 在调用 NgAfterViewInit 回调函数之前就会设置这些视图查询. 元数据属性: selector - 用于查询的指令类型或名字. read - 从查询到的元素中读取另一个 ...

随机推荐

  1. Linux下的ACL

    ACL理论概述 9位的属主/属组/其他人访问控制系统已经得到证明是强大的,足以满足大多数管理方面的需求. 事实上,在所有非UNIX操作系统上都采用了一种实质上更为复杂的方式来管理对于文件的访问:访问控 ...

  2. [ CodeVS冲杯之路 ] P1220

    不充钱,你怎么AC? 题目:http://codevs.cn/problem/1220/ 一个标准的DAG上的DP,设 f[i][j] 为在第 i 行第 j 最大分数 因为这个状态是无后效性的,所以可 ...

  3. WIN8下笔记本共享热点的设置

    C:\windows\system32>netsh wlan start hostednetwork 无法启动承载网络. 组或资源的状态不是执行请求操作的正确状态. 解决方法: http://j ...

  4. js比对一维数组全等的算法

    //辅助方法1,返回某个值在数组中的位置 Array.prototype.indexOf = function (e) { for (var i = 0, l = this.length; i < ...

  5. HDU 1166.敌兵布阵-完全版线段树(单点增减、区间求和)

    生活艰辛,且行且珍惜. 先水一篇博客再去补题,要不然又忘记写博客了. 计划系统的刷一遍线段树专题,自己给自己找虐(自作孽不可活),从基础的到后面的,所有的都挂了题,刷题不,大兄弟? 线段树可真有意思, ...

  6. codeforces-723D

    题目连接:http://codeforces.com/contest/723/problem/D D. Lakes in Berland time limit per test 2 seconds m ...

  7. Shellcode开发辅助工具shellnoob

    Shellcode开发辅助工具shellnoob   Shellcode开发的过程中会遇到很多繁杂的工作,如编译.反编译.调试等.为了减少这部分工作,Kali Linux提供了开发辅助工具shelln ...

  8. [BZOJ 1567] Blue Mary的战役地图

    Link: BZOJ 1567 传送门 Solution: 矩阵Hash/二维$Hash$模板题 涉及到需要快速查询.匹配的题目,考虑直接上$Hash$ 矩阵$Hash$其实就是每行先各$Hash$一 ...

  9. 【bzoj4152】【The Captain】最短路(堆优化)(浅尝ACM-B)

    [pixiv] https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62834538 Description 给定平面上 ...

  10. List集合-保存和输出宠物信息

    package collection; /** * 宠物类 * @author * */ public class Pet { private String name; private String ...