Why is Angular asking for an standalone component, even though it is

Pretty much what the title says, I can’t find what I’m doing wrong. Here’s the code for circulo.component.ts:

import { Component, OnInit } from '@angular/core';
import { Circulo } from '../figura-geometrica';

@Component({
  selector: 'app-circulo',
  templateUrl: './circulo.component.html',
  styleUrls: ['./circulo.component.scss'],
  standalone: true,
})
export class CirculoComponent extends Circulo implements OnInit {

  override radio: number = 0;

  constructor(nombre:string, radio:number) {
    super(nombre, radio)
    this.radio = radio;
  }

   ngOnInit() {}

   override calcularPerimetro(): number {
    return this.radio * 2 * 3.1416
  }


}

This is what it’s importing on the second line from circulo.component.ts, figura-geometrica.ts:

export abstract class FiguraGeometrica {
    nombre : string = "";

    constructor(nombre:string) {
        this.nombre = nombre;
    }

    abstract calcularPerimetro(): number
}

export class Circulo extends FiguraGeometrica {
    radio : number = 0;

    constructor(nombre:string, radio:number) {
        super(nombre)
        this.radio = radio;
    }
    override calcularPerimetro(): number {
        return this.radio * 2 * 3.1416
    }
}

export class TrianguloEscaleno extends FiguraGeometrica {

    ladoA : number = 0;
    ladoB : number = 0;
    ladoC : number = 0;

    constructor(nombre:string, ladoA:number, ladoB:number, ladoC:number) {
        super(nombre)
        this.ladoA = ladoA;
        this.ladoB = ladoB;
        this.ladoC = ladoC;
    }
    override calcularPerimetro(): number {
        return this.ladoA + this.ladoB + this.ladoC
    }
}

export class TrianguloEquilatero extends TrianguloEscaleno {    
    constructor(nombre:string, ladoA:number, ladoB:number, ladoC:number){
        super(nombre, ladoA, ladoB, ladoC)
    }
}

Now this is where I get the problem, home.page.ts:

import { Component } from '@angular/core';
import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
import { CirculoComponent } from "../modelo/circulo/circulo.component";

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
  imports: [IonHeader, IonToolbar, IonTitle, IonContent, CirculoComponent], <- there
  standalone: true,
})
export class HomePage {
  constructor() {}
}

imports: [IonHeader, IonToolbar, IonTitle, IonContent, CirculoComponent], <- that’s what is giving me the problem, which is this:

Component imports must be standalone components, directives, pipes, or must be NgModules.(-992012)

I also think that figura-geometrica.ts is unnecessary, but that’s how my teacher has done it, but with an easier example.

3

  1. You need to add the IonInput, IonItem, and IonList components to the imports array for CirculoComponent.
import { IonInput, IonItem, IonList } from '@ionic/angular/standalone';

@Component({
  ...,
  imports: [IonInput, IonItem, IonList],
})
export class CirculoComponent extends Circulo implements OnInit {
  ...
}
  1. The arguments in the constructor of a component are dependency injectors. For your scenario, you need to add/register the Injection Token for nombre and radio into the providers either for the component or the root application/module. Next, use the @Inject() decorator to get the value from DI.
import { Component, Inject, OnInit } from '@angular/core';
import { IonInput, IonItem, IonList } from '@ionic/angular/standalone';

@Component({
  selector: 'app-circulo',
  templateUrl: './circulo.component.html',
  styleUrls: ['./circulo.component.scss'],
  standalone: true,
  imports: [IonInput, IonItem, IonList],
  providers: [
    { provide: 'nombre', useValue: 'test' },
    { provide: 'radio', useValue: 1 },
  ],
})
export class CirculoComponent extends Circulo implements OnInit {
  constructor(
    @Inject('nombre') nombre: string,
    @Inject('radio') radio: number
  ) {
    super(nombre, radio);
    this.radio = radio;
  }
}

For adding the injection token to the root application:

bootstrapApplication(App, {
  providers: [
    ...,
    { provide: 'nombre', useValue: 'test' },
    { provide: 'radio', useValue: 1 },
  ],
});

Demo @ StackBlitz

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật