2
我準備發送給api的模型需要dd-mm-yyyy形式的DoB。更好的建立多場模型/值的角度方法?
即
vm.Manifest = {
Driver: {
dateOfBirth: "17-11-1969"
},
};
我的觀點有三個獨立的字段。
我想我可以做什麼是有串接在即時三個字段的隱藏字段:
<div class="form-group">
<label class="col-sm-2 col-form-label text-right">Date of Birth:</label>
<div class="col-md-5">
<select ng-model="adminManifestVm.Manifest.Driver.Day"
ng-options="day.val as day.name for day in adminManifestVm.controls.days"
name="Day"
class="form-control input-inline input-small"
required>
<option value="">Day</option>
</select>
<select ng-model="adminManifestVm.Manifest.Driver.Month"
ng-options="month.val as month.name for month in adminManifestVm.controls.months"
name="Month"
class="form-control input-inline input-small"
required>
<option value="">Month</option>
</select>
<select ng-model="adminManifestVm.Manifest.Driver.Year"
ng-options="year for year in adminManifestVm.controls.yearsAge"
name="Year"
class="form-control input-inline input-small"
required>
<option value="">Year</option>
</select>
<!-- this field is hidden but contains the formatted date -->
<input type="text" name="dateOfBirth"
ng-value="adminManifestVm.Manifest.Driver.Day +
'-' +
adminManifestVm.Manifest.Driver.Month +
'-' +
adminManifestVm.Manifest.Driver.Year">
<div class="error-message" ng-show="manifestForm.$invalid && (manifestForm.Day.$touched && manifestForm.Month.$touched && manifestForm.Year.$touched) || adminManifestVm.submitted">
<span ng-show="manifestForm.$error.required">Your full birth date is required.</span>
</div>
</div>
</div>
它的工作原理,但有一個更加棱角分明的方式來做到這一點?
感謝。關於這個的一些問題。 1]我要傳遞給API的對象在開篇文章(vm.Manifest)中指定。這個驅動程序方法是它自己的方法,對嗎?將它標記爲vm.DriverDoBetter或其他東西是否合理? 2]我不能直接將函數*指向API - 它嵌套在vm.Manifest中。所以我想我需要做一些vm.Manifest.driver.dateOfBirth = vm.DriverDBSetter.dateOfBirth() – DaveC426913
你可以像你所說的那樣做'vm.Manifest.driver.dateOfBirth = vm.DriverDBSetter.dateOfBirth()'發佈到API時。所以你的用戶界面將綁定到一個不同於你發送給API的對象。 –
啊。得到它的工作。謝謝!現在我知道如何使用gettersetters。 – DaveC426913