从子组件中,使用 Angular 输出,我发出一个字符串值。我想要的是,在父组件中,我将收到该字符串并将与现有值连接。
父组件有一个名为customValue: string;
现在这些代码正在工作customValue = customValue+ $event +' '
<parent>
<child (stringValue)="customValue = customValue+ $event +' '"> </child>
</parent>
但是如果我尝试像这样连接: customValue += $event +' '
那么它不起作用。
<parent>
<child (stringValue)="customValue += $event +' "> </child>
</parent>
有人可以告诉我为什么上面的字符串连接不起作用吗?
请注意:我真的不想创建一个函数。有什么方法可以在不创建函数的情况下实现我想要的功能吗?
最佳答案
来自the angular docs :
The following JavaScript and template expression syntax is not allowed:
new
increment and decrement operators, ++ and -- operator
assignment, such as += and -=
the bitwise operators, such as | and & operator
模板不支持某些 JavaScript 功能
关于angular - 来自 Angular 输出的字符串连接发出,未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65234014/