-1

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

    }
}
Lars
  • 920
  • 1
  • 14
  • 34
  • One of the solutions would be to transform your data directly into your .ts file. Could you try something like this ? https://stackoverflow.com/a/45818325/6444705 – Emilien Mar 29 '22 at 12:40
  • @Emilien thx for your answer. The problem with this is that my example is very simplified. In real world I have 4 sequential pipes. Each pipe contains values from the UI. In other words: it would be probably possible but with a very huge effort. So a simpler solution would be needed – Lars Mar 29 '22 at 14:39

1 Answers1

0

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

    }
}
  • Please can you explain what it should do? I mean `objectlist` is a list WHICH already in the component (all unmodified elements). But applying pipes on this list in the template would not change the `objectlist` itself, would it? – Lars Mar 29 '22 at 14:43
  • I mean we can use method with *ngIf="methodName()" and add method in component and process the objectlist with pipes in @component() class. – Mudassar Mustafai Mar 29 '22 at 15:06
  • you can inject pipe with in component class and transform the value with in component class. – Mudassar Mustafai Mar 29 '22 at 15:09
  • Pls can you give an example, because I'm not really understand what or how do you mean this? – Lars Mar 29 '22 at 16:34