管道';异步';在Angular+;斯巴达克斯
如上所述,当我尝试使用async关键字时,我遇到了浏览器错误。我正在自定义模块中导入CommonModule。找不到它不工作的原因 错误:管道';异步';在Angular+;斯巴达克斯,angular,spartacus-storefront,Angular,Spartacus Storefront,如上所述,当我尝试使用async关键字时,我遇到了浏览器错误。我正在自定义模块中导入CommonModule。找不到它不工作的原因 错误: ERROR Error: The pipe 'async' could not be found! Angular 2 getPipeDef$1 pipe 模块 import { NgModule } from '@angular/core'; import { CommonModule } from '@angul
ERROR Error: The pipe 'async' could not be found!
Angular 2
getPipeDef$1
pipe
模块
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
@NgModule({
imports: [
CommonModule
]
})
export class IngenicoPaymentMethodModule { }
我的组件
import { Component, OnInit } from '@angular/core';
import { ActiveCartService, UserIdService } from '@spartacus/core';
import { Observable } from 'rxjs';
import { PaymentMethodService, PaymentProduct } from './facade/payment-method.service';
@Component({
selector: 'app-ingenico-payment-method',
templateUrl: './ingenico-payment-method.component.html',
styleUrls: ['./ingenico-payment-method.component.scss']
})
export class IngenicoPaymentMethodComponent implements OnInit {
paymentMethods$: Observable<PaymentProduct[]>;
constructor(
protected paymentMethodService: PaymentMethodService,
protected activeCartService: ActiveCartService,
protected userIdService: UserIdService) { }
ngOnInit(): void {
let userId, cartId;
this.userIdService.getUserId()
.subscribe(occId => userId = occId)
.unsubscribe();
this.activeCartService.getActiveCartId().subscribe(occId => cartId = occId).unsubscribe();
if (userId && cartId) {
this.paymentMethods$ = this.paymentMethodService.getPaymentMethods(userId, cartId);
}
}
}
从'@angular/core'导入{Component,OnInit};
从'@spartacus/core'导入{ActiveCartService,UserIdService};
从“rxjs”导入{Observable};
从“./facade/paymentmethod.service”导入{PaymentMethodService,PaymentProduct};
@组成部分({
选择器:“app ingenico付款方式”,
templateUrl:'./ingenico payment method.component.html',
styleUrls:['./ingenico支付方法.component.scss']
})
导出类IngenicoPaymentMethodComponent实现OnInit{
支付方式:可观察;
建造师(
受保护的paymentMethodService:paymentMethodService,
受保护的activeCartService:activeCartService,
受保护的userIdService:userIdService){}
ngOnInit():void{
让userId,cartId;
this.userIdService.getUserId()
.subscribe(occId=>userId=occId)
.取消订阅();
this.activeCartService.getActiveCartId().subscribe(occId=>cartId=occId.unsubscribe();
if(userId&&cartId){
this.paymentMethods$=this.paymentMethodService.getPaymentMethods(userId,cartId);
}
}
}
模板
<ng-container *ngIf="paymentMethods$ | async as paymentMethods"></ng-container>
正如您在上面看到的,我正在导入CommonModule,但它在浏览器中不可见。您可以通过设置:
"angularCompilerOptions": {
"enableIvy": false
}
在您的
tsconfig.app.json中,这将解决您的问题。请在导入CommonModule
的同一模块中声明您的组件。只有在组件的模板中才能访问async
管道:
@NgModule({
进口:[
公共模块
],
声明:[IngenicoPaymentMethodComponent]//您在哪个模块中定义了IngenicoPaymentMethodComponent
component?您能帮助我理解选择离开常春藤有助于解决这个问题吗?乍一看,这似乎与我无关。。。
"angularCompilerOptions": {
"enableIvy": false
}