angular - 如何使用角反应形式的字符串插值传递值
问题描述
我有一个帖子列表,每个帖子都有帖子评论表单,我正在尝试为每个帖子发送带有评论表单的帖子 ID,但它不起作用..
我试过用
<form class="comment-form inline-items" [formGroup]="form2" (ngSubmit)="onSubmitComment()">
<div class="post__author author vcard inline-items">
<img src="{{user.photo}}" alt="author">
<h1>{{post.id}}</h1> <!-- it's working here -->
<div class="form-group with-icon-right ">
<textarea class="form-control" placeholder="" name="body" formControlName="body"></textarea>
<input type="text" value={{post.id}} name="id" formControlName="id"/> <!-- it's not working here -->
</div>
</div>
<button class="btn btn-md-2 btn-primary">Post Comment</button>
</form>
我希望发送带有评论的帖子 ID,但它发送空值
解决方案
这是我制作的Stackblitz 。您可以id
在提交函数中看到正在传递的内容,并且(可选)输入字段中的更改反映在模型中。
让我知道这是否是你所追求的
推荐阅读
- android - Ionic cordova compile failed for Android package 不存在
- windows - 具有代理流量功能的 Windows 应用程序选择哪个 Windows 平台
- spring - 如何在 Spring Boot 应用程序中使用模型数据从一个控制器方法重定向到另一种方法
- python - 尝试一起使用 ftplib 和 discord.py .. 有一些问题
- java - 如何将图像发送到 JSP 中的输出
- python - 根据另一列唯一值填充另一列
- symfony - DSN_MAILER 与主机 02switch
- spring-batch - 春季批处理编写器中的自定义 CSV 字段名称
- python - 使用正则表达式在标签和标签列表之间查找元素
- amazon-web-services - aws s3 ls 完全匹配