[Angular] @ContentChildren and QueryList
We have looked at @ContentChild in article(http://www.cnblogs.com/Answer1215/p/6414657.html).
Now let's how to query multi children by using @ContentChildren and QueryList.
First of all, let's add few more auth-remember component into our form component.
<auth-form
(submitted)="loginUser($event)">
<h3>Login</h3>
<auth-remember
[role]="'checkbox1'"
(checked)="rememberUser($event)">
</auth-remember>
<auth-remember
[role]="'checkbox2'"
(checked)="rememberUser($event)">
</auth-remember>
<auth-remember
[role]="'checkbox3'"
(checked)="rememberUser($event)">
</auth-remember>
<button type="submit">
Login
</button>
</auth-form>
Then inside auth-form component, we can query all the auth-remember components:
@ContentChildren(AuthRememberComponent) remembers: QueryList<AuthRememberComponent>;
Then lot out in the ngAfterContentInit lifecycle:
ngAfterContentInit(): void {
if(this.remembers) {
this.remembers.forEach((item: AuthRememberComponent, i: number) => {
console.log("item:", item);
item.checked.subscribe((checked: boolean) => {
console.log(`${i}: checked`, checked);
})
});
}
}

[Angular] @ContentChildren and QueryList的更多相关文章
- [Angular] Communicate Between Components Using Angular Dependency Injection
Allow more than one child component of the same type. Allow child components to be placed within the ...
- [Angular] Angular Advanced Features - ng-template , ng-container, ngTemplateOutlet
Previously we have tab-panel template defined like this: <ul class="tab-panel-buttons" ...
- Angular template ng-template/container/content
1. ng-template 形式:<ng-template>...</ng-template> 默认ng-template中的内容会隐藏; 可通过[ngIf]来控制内容显示隐 ...
- Angular5 父组件获取子组件实例( ViewChildren、ViewChild用法)
原文链接 Understanding ViewChildren, ContentChildren, and QueryList in Angular 使用场景 有时候,我们想要在父组件中访问它的子组件 ...
- [Angular 2] More on *ngFor, @ContentChildren & QueryList<>
In previous artical, we introduce the how to use *ngFor. The limitation for previous solution to dis ...
- Angular开发实践(三):剖析Angular Component
Web Component 在介绍Angular Component之前,我们先简单了解下W3C Web Components 定义 W3C为统一组件化标准方式,提出Web Component的标准. ...
- Angular 学习笔记 ( CDK - Accessibility )
@angular/ckd 是 ng 对于 ui 组建的基础架构. 是由 material 团队开发与维护的, 之所以会有 cdk 看样子是因为在开发 material 的时候随便抽象一个层次出来给大家 ...
- 转发: Angular装饰器
Angular中的装饰器是一个函数,它将元数据添加到类.类成员(属性.方法)和函数参数. 用法:要想应用装饰器,把它放在被装饰对象的上面或左边. Angular使用自己的一套装饰器来实现应用程序各部件 ...
- Angular ContentChild
contentchild // 使用方法 git clone https://git.oschina.net/mumu-osc/learn-component.git cd learn-compone ...
随机推荐
- secureCRT The remote system refused the connection问题解决
问题: Ubuntu系统必须开启ssh服务后,XP或者其它的主机才干够远程登陆到Ubuntu系统. 1,安装软件包,运行sudo apt-get install openssh-server Ubun ...
- PHPki
PHPki PHPki是一个基于开放源码Web的应用程序,用来管理遵守HIPAA的多代理"公钥基础结构".它可以用于创建X.509数字证书,并主要为支持S/MIME的电子邮件客户端 ...
- $(dom).each(index,ele){} 真正的jquery对象
1.$(ele)才是each真正的jquery对象,而不是ele.$('.mt-story-info').each(function(index,ele){ if($('.mt-story-info' ...
- 韦东山网课https://edu.csdn.net/course/play/207/1117
接口讲解https://edu.csdn.net/course/play/207/1117
- 自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画
自己定义progressdialog载入动画,这里还有旋转的载入条,美团,多个图片动画 下载Demo:http://download.csdn.net/detail/menglele1314/8775 ...
- python把一个列表画柱状图
https://blog.csdn.net/w113691/article/details/80385534
- js课程 4-12 js中正则表达式如何使用
js课程 4-12 js中正则表达式如何使用 一.总结 一句话总结: 1.js正则表达式手册取哪里找? w3cschool或者菜鸟教程->找到js正则表达式->完整的RegExp参考手册这 ...
- mybatis-generator使用
开发工具:eclipse,依赖环境 :maven 首先在eclipse marketplace中安装mybatis-generator,如图: 安装后需要重启. 新建一个maven项目MybatisG ...
- Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument
spring 5.+jpa 配置类出错: 十二月 20, 2018 5:53:01 下午 org.springframework.web.servlet.DispatcherServlet initS ...
- php课程 1-3 字符串变量输出方式有哪些(总结:四种)
php课程 1-3 字符串变量输出方式有哪些(总结:四种) 一.总结 一句话总结:推荐使用双引号中加{$变量名}的形式(echo "my name is {$name}eee !" ...