[英]How can I get access to a template generated local variable to component code?
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?有什么干净的方法可以访问组件的 function 中的
filteredSkaterlist
吗? To send the filteredSkaterlist
as argument of eg the click()
is no option because the button is out of scope.将
filteredSkaterlist
作为参数发送,例如click()
不是一个选项,因为按钮不在 scope 之内。
@Component({...})
export class MyComponent {
...
download() {
// access value of filteredSkaterlist
}
}
Can you please try this way.你能试试这个方法吗?
<ng-container *ngIf="objectList()">
...
</ng-container>
I've defined objectList() method with structural directive of *ngIf.我已经用 *ngIf 的结构指令定义了 objectList() 方法。 We can define objectList() method in component class and return true or false depend on the condition.
我们可以在组件 class 中定义 objectList() 方法,并根据条件返回 true 或 false。
@Component({...})
export class MyComponent {
objectList() : boolean {
// access value class objects and return true false value
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.