[Angular] @ViewChild read custom directive and exportAs
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的更多相关文章
- Angular自定义指令(directive)
angular自定义指令,意我们可以通过angula自己定义指令,来实现我们的特殊要求,为所欲为,一支穿云箭,千军万马来相见 多少年的老规矩了,先看代码: <!DOCTYPE html> ...
- angular的GitHub Repository Directive Example学习
angular的GitHub Repository Directive Example学习 <!DOCTYPE html> <html ng-app="myApp" ...
- angular自定义指令-directive
Directive究竟是个怎么样的一个东西呢?我个人的理解是这样的:将一段html.js封装在一起,形成一个可复用的独立个体,具体特定的功能.下面我们来详细解读一下Directive的一般性用法. v ...
- [Angular] Custom directive Form validator
Create a directive to check no special characters allowed: import {Directive, forwardRef} from '@ang ...
- Angular之 Scope和 Directive
---------------------------Scope-------------------------------- https://docs.angularjs.org/guide/sc ...
- [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 ...
- Angular 学习笔记 (Custom Accessor + Mat FormField + Custom select)
custom form control 之前就写过了,这里简单写一下. 创建一个组件实现 ControlValueAccessor 接口 @Component({ providers: [ { pro ...
- -_-#【Angular】自定义指令directive
AngularJS学习笔记 <!DOCTYPE html> <html ng-app="Demo"> <head> <meta chars ...
- angular ViewChild ContentChild 系列的查询参数
官方说明 官方文档 在调用 NgAfterViewInit 回调函数之前就会设置这些视图查询. 元数据属性: selector - 用于查询的指令类型或名字. read - 从查询到的元素中读取另一个 ...
随机推荐
- 【飞天奔月出品】memcached四大注意事项(key长度,空格限制,最大item)
1. key值最大长度? memcached的key的最大长度是250个字符. 注意250是memcached服务器端内部的限制(可以修改) 如果您使用的客户端支持"key的前缀&quo ...
- Robocopy用法
----------------[参数]-------------------robocopy /?------------------------------------------------- ...
- java算法(一) 直接选择排序
一.基本概念 首先在未排序序列中找到最小(大)元素,存放到排序序列的起始位置(注:要把最大最小的元素和起始的元素交换), 然后,再从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾.以 ...
- ubuntu 解压
.tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) ---------------------- ...
- usb驱动---What is the difference between /dev/ttyUSB and /dev/ttyACM【转】
转自:http://blog.csdn.net/ppp2006/article/details/25654733 https://www.rfc1149.net/blog/2013/03/05/wha ...
- java基础练习 14
import java.util.Scanner; public class Fourtheen { /*打印出所有的"水仙花数",所谓"水仙花数"是指一个三位 ...
- dnspod 批量添加记录
#!/usr/bin/python #-*- coding: utf-8 -*- import os,requests,json import re,xlsxwriter,time import xl ...
- 牛客网 牛客练习赛7 A.骰子的游戏
A.骰⼦的游戏 时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 32768K,其他语言65536K64bit IO Format: %lld 题目描述 在Alice和Bob面前的是两个骰 ...
- ZOJ18th省赛 Lucky 7
[线上网址](http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=378) BaoBao has just found ...
- bzoj2301(莫比乌斯反演)
bzoj2301 题意 求区间 [a, b] 和 区间 [c, d] 有多少对数 (x, y) 使得 gcd(x, y) = k . 分析 参考ppt 参考blog 考虑用容斥分成四次查询, 对于每次 ...