angular - mat-select中的Angular Material ngTemplateOutlet不起作用
问题描述
我有一个数据树结构,我想mat-options
通过递归遍历树来填充。我认为使用它很容易实现,ngTemplateOutlet
但由于某种原因,这会破坏mat-select
绑定。垫子选项出现,当您单击它们时,它们的状态将变为“活动”,但它们不会绑定到mat-select
对象(例如,单击不会关闭选择框)。
有没有办法实现我正在寻找的功能?另外,什么原理导致我看到的行为?
这是正在发生的事情的演示:https ://stackblitz.com/edit/angular-dvtq8h
这是组件的 html 的副本:
<mat-form-field>
<mat-select placeholder="Favorite food">
<mat-option [value]="'a'">A</mat-option>
<mat-option [value]="'b'">B</mat-option>
<ng-container *ngTemplateOutlet="otherOptions"></ng-container>
</mat-select>
</mat-form-field>
<ng-template #otherOptions>
<mat-option [value]="'c'">Other</mat-option>
</ng-template>
解决方案
推荐阅读
- ruby-on-rails - 为什么枚举不像文档中所宣传的那样工作?
- php - fwrite():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:140D00CF:SSL 例程:SSL_write:协议已关闭
- javascript - 给定模式的正则表达式
- node.js - 创建连接时关闭连接猫鼬
- node.js - 在测试中模拟对外部服务的 axios 请求
- c# - ConcurrentStack:如何检查是否包含对象?
- deepstream.io - Deepstream 1 - n 关系
- oracle - ORA-01861 仅在发布到 IIS 时引发错误
- log4j - 在 log4j 版本 1 中动态更改日志级别并桥接到版本 2
- python - 熊猫比较多索引数据帧而不循环