angular - Angular 中子组件的问题

标签 angular parent-child angular-components

这是我的项目:https://stackblitz.com/edit/planificador?file=src/app/planificador/components/resumen/resumen.component.ts

我有一个 MainContentComponent(父组件),其中有几个子组件

maincontent.html

现在我看到在 ContratosComponent 中完美地获取了 proyectoId,但在 ResumenComponent 中我得到了未定义

undefined

ngOnInit

inputs

请问有什么想法吗?

最佳答案

我运行 stackblitz,似乎两个组件都正确返回了 proyectoId - 所以我认为它可能还依赖于其他一些东西并且不容易重现?

您的问题可能是 proyecto$可观察来自BehaviourSubject 。这意味着如果没有值被推送到该主题,它将发出 null。

您的 ngIf <div *ngIf="proyecto$ | async as proyecto">一旦 observable 发出,就会返回 true。所以,如果没有proyecto被推送到BehaviourSubject ,它将返回 true 和 proyecto将为空。这可能是导致您出现问题的原因。

同样,这很难说,因为似乎存在一些竞争条件,导致问题并不总是发生。

关于angular - Angular 中子组件的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66777632/

相关文章:

angular - 在 url 上隐藏路由 Angular 2+

c++ - 如何将分配给 *Child[n] 的 *Base 指向 Child 数组的下一个元素?

javascript - 从 api 返回 true false 的 Angular 过滤器?

html - AngularJS - 将值传递给组件

javascript - angular2 - 从父路由到子路由的传递值

angular - 为什么我的 header 在 angular 7 中没有响应?

angular - 如何显示跟随角色的文字?

C++ : Extend object by downcasting to derived class

c# 从父列表调用子方法

javascript - 如何监听 AngularJS 组件中的事件?