如何访问角材料组件的属性? [英] How to access properties of angular material components?

查看:24
本文介绍了如何访问角材料组件的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

总的来说,我对 angular 还是比较陌生,我已经用它构建了我的前几个应用程序,现在我正在处理一些包含 angular 材料的项目.

I'm fairly new to angular in general, i have built my first few apps with it and right now I'm working on some project that contains angular material.

当我访问 this 站点时,我看到了许多 MatSelect 指令的属性.我想以某种方式访问​​一个名为empty: boolean"的属性,但我不知道如何访问,你能帮我吗?

When i go to this site i see lots of properties of the MatSelect directive. There is one property called 'empty: boolean' that I would like to access in some way, but i don't know how, can you help me?

推荐答案

注意Exported as:matSelect.您可以通过模板引用变量(#var) 或 ViewChild 来引用它:

Pay attention to Exported as:matSelect. You can reference it by template reference variable(#var) or by ViewChild:

  <mat-select #matSelect = 'matSelect'>
  ...

component.ts:

   @ViewChild('matSelect') child: MatSelect; 
   //or
   @ViewChild(MatSelect) child: MatSelect; 

https://material.angular.io/components/select/api#MatSelect

演示示例

这篇关于如何访问角材料组件的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆