angular - 材质垫选择名称属性
问题描述
我正在研究一些简单的形式,将其从引导程序转换为材料。
尽管我正在使用 Angular 6,但表单在提交时以旧式发布(不使用角度表单)
<form method="post" action="http://api.example.com/submit" id="user_form">
<mat-form-field>
<input matInput placeholder="name" name="username">
</mat-form-field>
<mat-form-field>
<mat-select placeholder="user-type" name="usertype">
<mat-option value="type1">type1</mat-option>
<mat-option value="type2">type2</mat-option>
</mat-select>
</mat-form-field>
<button type="submit">submit</button>
</form>
为简单起见,我想保持这种方式,并且在提交此表单时不要使用任何 javascript(没有模板驱动的表单或反应式表单)。
在input
向 中添加name
属性时效果很好,imput
当我发布表单(单击提交按钮)时,它按预期发送到服务器。
至于mat-select
,此数据不会在发布数据中发送到服务器。我猜前者是原生的input
wheremat-select
是一个组件。
有没有办法使这项工作?(再次,在 TS 端不处理表单 POST)
解决方案
找到了答案。
只需select
像这样使用本机:
<select matNativeControl placeholder="user-type" name="usertype" required>
<option value="" disabled selected></option>
<option value="type1">type1</option>
<option value="type2">type2</option>
</select>
推荐阅读
- android-studio - 在颤振中没有为类“TextTheme”定义吸气剂“bodyText2”
- java - 如何比较arraylist java中的所有可能组合
- npm - 如何在lerna中增加版本?
- python - 带有 pybind 的多态类
- c# - 计算体重目标的百分比
- protocols - Ubuntu Remmina“未安装协议插件 RDP”错误,缺少 RDP
- python - 在保存到excel时将DataFrame值拆分为多列?
- java - 如何使用 LiveData 代替 LocalBroadcastManager
- vaadin - Vaadin 14.2:使用 BeforeLeaveListener 拦截注销(使会话无效)
- linux - 无法使用自制软件在 mac 中安装 JQ