[英]How do I change a variable in angular 6 using interpolation?
That's not how it works.这不是它的工作原理。 You'll have to somehow call
changeX
.你必须以某种方式调用
changeX
。 But you can only do that if there's any DOM event.但是只有在有任何 DOM 事件时才能这样做。 So I've added
changeX
as a click
event handler to the div
.所以我已经将
changeX
作为click
事件处理程序添加到div
。 Whenever the div
is clicked, x
will increment.每当单击
div
, x
都会增加。
{{x}}
<div (click)="changeX()">
wtf
</div>
{{x}}
Here's a StackBlitz for it.这是一个StackBlitz 。
this works for me:这对我有用:
in the component:在组件中:
@Output()
private x = 5;
public incX() {
this.x++;
}
in the template:在模板中:
{{x}}
<div>
wtf{{incX()}}
</div>
{{x}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.