How can I get access to a template generated local variable to component code?

355 views Asked by At

Maybe I'm thinking in the completely wrong direction. But what I would like to do is call the value of a variable, which was defined in the template, in the component.

<button (click)="download()">...</button>

<ng-container *ngIf="objectlist | filterSort: sortColumnService.sortTerm() as filteredSkaterlist">
    ...
</ng-container>

Is there any clean way to access filteredSkaterlist in a function of the component? To send the filteredSkaterlist as argument of e.g. the click() is no option because the button is out of scope.

@Component({...})
export class MyComponent {
    ...
    download() {

        // access value of filteredSkaterlist

    }
}
1

There are 1 answers

4
Mudassar Mustafai On

Can you please try this way.

<ng-container *ngIf="objectList()">
...
</ng-container>

I've defined objectList() method with structural directive of *ngIf. We can define objectList() method in component class and return true or false depend on the condition.

@Component({...})
export class MyComponent {
   
    objectList() : boolean {

        // access value class objects and return true false value

    }
}