angular - Angular 中子组件的问题
问题描述
我有一个 MainContentComponent (父级),其中有几个子组件
现在我看到在 ContratosComponent 内部例如完美地得到 proyectoId 但在 ResumenComponent 我得到未定义
请问有什么想法吗?
解决方案
我运行stackblitz,似乎两个组件都正确返回了proyectoId - 所以我认为它可能也取决于其他一些东西并且不容易复制?
您的问题可能是proyecto$
observable 来自BehaviourSubject
. 这意味着如果没有将值推送到该主题,它将发出 null。
<div *ngIf="proyecto$ | async as proyecto">
一旦 observable 发出,您的 ngIf就会返回 true。因此,如果没有将 proyecto 推送到BehaviourSubject
,它将返回 true 并且proyecto
将为 null。这可能是您的问题的原因。
同样,这很难说,因为似乎有一些竞争条件导致问题并不总是发生。
推荐阅读
- python - 使用 keras 加载模型文件时出错
- javascript - 如何将标签 css 从标签 1 转换为标签 2?
- python - 如何有效地格式化excel中的范围-AttributeError:'tuple'对象没有属性'fill'
- node.js - Joi 验证 - 不满足条件时不需要字段
- python - 以日期时间格式突出显示 %d 的问题
- java - 无法访问 org.apache.lucene.search.TotalHits
- sql - 根据一列中的层次标准选择行
- powerbi - PowerBI 表格可视化未显示所有行
- java - Webhook VS Rest 端点?它们是有区别的?
- asp.net - 具有不同域的 ASP.NET 表单身份验证重复 cookie