gpt4 book ai didi

javascript - 如何将表单字段作为 ng-include 包含在表单中?

转载 作者:行者123 更新时间:2023-11-30 12:44:20 26 4
gpt4 key购买 nike

Angular 相对较新,并尝试创建一个用于创建和编辑操作的表单。我希望分享一些表单字段,但据我了解,ng-include 创建了一个新范围,因此我的字段(使用 ng-model)未绑定(bind)到原来的范围。结果是提交表单时我的字段没有发送。

如果我以错误的方式解决这个问题,请指导我查看可能有帮助的任何文档。我的部分问题是我不确定从哪里看这一点。谢谢!

创建表单

<section data-ng-controller="AlbumsController">
<div class="page-header">
<h1>New Album</h1>
</div>
<form data-ng-submit="create()">
<section data-ng-include="'/modules/albums/views/form.html'"></section>
<input type="submit" class="btn btn-primary" value="Add Album">
</form>
</section>

形式部分

<fieldset class="well">
<div class="form-group">
<label class="control-label" for="name">Name</label>
<div class="controls">
<input type="text" data-ng-model="album.name" id="name" class="form-control" placeholder="Name" required>
</div>
</div>
<div class="form-group">
<label class="control-label" for="name">Album Picture</label>
<div class="controls">
<input type="text" data-ng-model="album.picture" id="picture" class="form-control" placeholder="Album Picture" required>
</div>
</div>
<div class="form-group">
<label class="control-label" for="releaseDate">Release Date</label>
<div class="controls">
<input type="date" data-ng-model="album.releaseDate" id="releaseDate" class="form-control" placeholder="Release Date" required>
</div>
</div>
<div class="form-group">
<label class="control-label" for="sku">SKU</label>
<div class="controls">
<input type="text" data-ng-model="album.sku" id="sku" class="form-control" placeholder="SKU" required>
</div>
</div>
</fieldset>

最佳答案

更改:<section data-ng-include="'/modules/albums/views/form.html'"></section>

至:<section data-ng-include src="'/modules/albums/views/form.html'"></section>

关于javascript - 如何将表单字段作为 ng-include 包含在表单中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23160626/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com