Angular basic change?

Discussão em 'Angular' iniciado por Blazor Experiencer, Outubro 4, 2024.

  1. I have a basic question about angular. I am following a course, but I think that has an old version, the code that should work does nog work in my case, I have an empty list. I uese the following parts of code :

    app.component.html
    <app-subject>[testList]="testset"</app-subject>

    app.module.ts :
    // in declarations added : TestComponent

    app.component.ts :
    export class AppComponent {
    testset: string[] = ['Test 1', 'Test 2', 'Test 3', 'Test 4' ];
    title = 'test in Angular';
    }

    subject.component.html :
    <u>
    @for (item of testList; track item ) {
    <li>{{ item }}</li>
    } @empty {
    <li>No items</li>
    }
    </u>

    subject.component.ts :
    // selector: 'app-test',
    export class TestComponent {
    @Input() testList: string[] = [];

    // following is working well:
    // @Input() testList: string[] = ['Test 1', 'Test 2', 'Test 3', 'Test 4' ];
    }


    Does anyone know this is a change, or am I using a wrong place to fill testset: string[] = ['Test 1', 'Test 2', 'Test 3', 'Test 4' ]; (export in app.component.ts)

    Like I wrote in comments :

    @Input() testList: string[] = ['Test 1', 'Test 2', 'Test 3', 'Test 4' ]; (export in subject.component.ts) Does work, but to work further on the example I would like to know if it there is another possibility.

    Continue reading...

Compartilhe esta Página