signals return error: is not a function at Object.computation

Discussão em 'Angular' iniciado por goldax, Novembro 27, 2024.

  1. goldax

    goldax Guest

    this is my cart service code:

    export class ManageCartItemsService {
    cartItems=signal<CartProductModel[]>([]);
    item={} as CartProductModel;
    }


    and this is my code for showing cart items count in other component:


    export class CartIconComponent implements OnInit{

    cartItemCounter:Signal<number>=computed(()=>this._ManageCartItemsService.cartItems().reduce(
    (acc,item)=>acc+item.quantity,0
    ));

    constructor(private _ManageCartItemsService:ManageCartItemsService){}

    }

    and i get this error:


    ERROR TypeError: this._ManageCartItemsService.cartItems is not a function
    ​

    Continue reading...

Compartilhe esta Página