Angular 是否可以绑定一个函数,将一个可观测值返回给@Input?

Angular 是否可以绑定一个函数,将一个可观测值返回给@Input?,angular,rxjs,Angular,Rxjs,我是angular 7应用程序,其中包含许多不同类型的认证和这些认证的应用程序。在创建新应用程序的过程中,我必须根据证书类型和实例化的应用程序从数据服务器加载数据。由于从服务返回的rxjs可观测数据的异步性质,我试图将所有数据作为可观测数据从一个组件传递到另一个组件 根据我所阅读的内容和我在这里看到的其他问题的答案,我尝试实例化的组件的模板中有以下代码: new-bcaba.component.html-模板 <div class="open-card-BG" *ngIf="Curre

我是angular 7应用程序,其中包含许多不同类型的认证和这些认证的应用程序。在创建新应用程序的过程中,我必须根据证书类型和实例化的应用程序从数据服务器加载数据。由于从服务返回的rxjs可观测数据的异步性质,我试图将所有数据作为可观测数据从一个组件传递到另一个组件

根据我所阅读的内容和我在这里看到的其他问题的答案,我尝试实例化的组件的模板中有以下代码:

new-bcaba.component.html-模板

  <div class="open-card-BG" *ngIf="CurrentPage == 1">
    <instructions [InstCertType]="ParentCertType$ | async" [InstAppType]="ParentAppType$ | async"></instructions>
  </div>

new-bcaba.component.ts-Typscript

export class NewBcabaComponent extends ApplicationComponent implements OnInit {

  //public ParentCertType$: Observable<CertType>;
  //public ParentAppType$: Observable<AppType>;

  public constructor(NewInject: Injector) { 
    super(NewInject, '2', '1', 11);
  }

  ngOnInit() {
    super.ngOnInit();
    //this.ParentCertType$ = this.ShowCertType();
    //this.ParentAppType$ = this.ShowAppType();
  }

  private ShowCertType() : Observable<CertType> {
    console.log("... ShowCertType called ... ");
    return this.BaseCertType$;
  }

  private ShowAppType() : Observable<AppType> {
    console.log("... ShowAppType called ... ");
    return this.BaseAppType$;
  }

  // Accessors
  public get ParentCertType$() : Observable<CertType> {
    return this.ShowCertType();
  }

  public get ParentAppType$() : Observable<AppType> {
    return this.ShowAppType();
  }
导出类NewCabaComponent扩展了ApplicationComponent在NIT上的实现{
//public ParentCertType$:可见;
//publicparentapptype$:可见;
公共构造函数(NewInject:Injector){
超级(2,1,11);;
}
恩戈尼尼特(){
super.ngOnInit();
//this.ParentCertType$=this.ShowCertType();
//this.ParentAppType$=this.ShowAppType();
}
私有ShowCertType():可观察{
log(“…ShowCertType调用…”);
返回此.BaseCertType$;
}
私有ShowAppType():可观察{
log(“…ShowAppType调用…”);
返回此.BaseAppType$;
}
//访问者
public get ParentCertType$():可观察{
返回此.ShowCertType();
}
public get ParentAppType$():可观察{
返回此.ShowAppType();
}
我尝试过直接使用访问器和设置成员变量,但这两种方法都会导致相同的错误

... ShowCertType called ...                           new-bcaba.component.ts:27 
... GetCertType in Certification Component called ... certification.component.ts:49
... FindCertType in Model-tools.service called ...                  model-tools.service.ts:53
... GetCertTypes in Model-tools.service called ...                  model-tools.service.ts:48

ERROR TypeError: fn is not a function                  NewBcabaComponent.html:3
    at pipe.js:18
    at Array.reduce (<anonymous>)
    at piped (pipe.js:18)
    at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.pipe (Observable.js:91)
    at ModelToolsService.push../src/app/_services/model-tools.service.ts.ModelToolsService.FindCertType (model-tools.service.ts:55)
    at NewBcabaComponent.push../src/app/certification/certification.component.ts.CertificationComponent.GetCertType (certification.component.ts:50)
    at NewBcabaComponent.get [as BaseCertType$] (certification.component.ts:54)
    at NewBcabaComponent.push../src/app/certification/application/new-bcaba/new-bcaba.component.ts.NewBcabaComponent.ShowCertType (new-bcaba.component.ts:28)
    at NewBcabaComponent.get [as ParentCertType$] (new-bcaba.component.ts:37)
    at Object.eval [as updateDirectives] (NewBcabaComponent.html:3)
…ShowCertType调用…新的bcaba.component.ts:27
…GetCertType在名为…Certification.Component.ts:49的认证组件中
…FindCertType在Model-tools.service中调用…Model-tools.service.ts:53
…Model-tools.service中的GetCertTypes称为…Model-tools.service.ts:48
错误类型错误:fn不是函数NewBcabaComponent.html:3
at pipe.js:18
在Array.reduce()处
在管道上(pipe.js:18)
at Observable.push../node_modules/rxjs/_esm5/internal/Observable.js.Observable.pipe(Observable.js:91)
位于ModelToolsService.push../src/app/_services/model-tools.service.ts.ModelToolsService.FindCertType(modeltools.service.ts:55)
在NewBcabaComponent.push../src/app/certification/certification.component.ts.CertificationComponent.GetCertType(certification.component.ts:50)
在NewBcabaComponent.get[as BaseCertType$](certification.component.ts:54)
在NewCabacomponent.push../src/app/certification/application/new-bcaba/new-bcaba.component.ts.newCabacomponent.ShowCertType(new-bcaba.component.ts:28)
在NewBcabaComponent.get[as ParentCertType$](新的bcaba.component.ts:37)
at Object.eval[作为updateDirectives](NewBcabaComponent.html:3)
根据console.log消息,问题似乎在于我如何将可观察对象绑定到模板,但根据我所读的内容,它看起来是正确的。我做错了什么吗?

是的。这是可能的

我创建了一个简单的代码,以显示您这样做有多容易:

如果您想更正代码,我想您应该按如下方式更改模板:

<div class="open-card-BG" *ngIf="CurrentPage == 1">
   <instructions [InstCertType]=ParentCertType$ 
  [InstAppType]=ParentAppType$></instructions>
</div>

是的,这是可能的

我创建了一个简单的代码,以显示您这样做有多容易:

如果您想更正代码,我想您应该按如下方式更改模板:

<div class="open-card-BG" *ngIf="CurrentPage == 1">
   <instructions [InstCertType]=ParentCertType$ 
  [InstAppType]=ParentAppType$></instructions>
</div>


为什么您不尝试使用服务在组件之间共享数据?如果您不知道如何实现,我可以编写这样的代码作为答案。我开始尝试,但无法使其用于组件创建。问题是从数据库服务器返回的数据具有异步性质。我可以使用sub脚本一旦创建组件,但当我需要数据来实例化嵌套组件时,它就会出现问题。我传递观察值,希望在数据可用时创建和初始化组件。每个应用程序嵌套10-15个组件,需要多个服务调用来构建一个应用程序初始化。检查rxjs运算符的导入,确保没有从内部包导入。错误似乎出现在ModelTools服务中,可能与组件本身或模板无关。@cgTag I从rxjs/operators导入运算符。我找到了停止错误的方法,但我不明白它为什么会起作用。I实际上,我已经创建了一个单独的问题,看看是否有人可以解释。为什么不尝试使用服务在组件之间共享数据?如果您不知道如何做到这一点,我可以编写这样的代码作为答案。我开始尝试,但无法让它用于组件创建。问题是数据的异步性质从数据库服务器返回。创建组件后,我可以使用它处理订阅,但当我需要数据来实例化嵌套组件时,它会出现问题。我传递观察值,希望在数据可用时创建并初始化组件。每个组件嵌套10-15个组件生成一个应用程序需要应用程序调用和多个服务调用。请检查rxjs运算符的导入,并确保未从内部包导入。错误似乎出现在ModelToolsService中,可能与组件本身或模板无关。@cgTag I从rxjs/operators.I导入运算符找到了一种阻止错误的方法,但我不明白它为什么会起作用。我实际上创建了一个单独的问题,看看是否有人能解释它。这对问题的一部分起作用,因为事实证明问题是三个不同的t