我想以下面的形式提交json对象:
object { id:1, version:0, roomNo:1, availability:"available", facility:{'a', 'b', 'c', 'd'} }
我的表格图片如下
angular material chips form image
<div flex="10" id="lenth">
<div ng-controller="roomController as controller" ng-cloak="" class="inputdemoErrors">
<div class="card">
<form ng-submit="controller.submit()" name="roomForm" >
<input type="hidden" ng-value="roomDTO.id" ng-model="roomDTO.id" />
<input type="hidden" ng-value="roomDTO.version" ng-model="roomDTO.version" />
<md-toolbar class="md-hue-2" ><div class="md-toolbar-tools"><span>{{roomHomeTitle}}</span></div></md-toolbar>
<div id="formBody">
<md-input-container class="md-block">
<label>Room no</label>
<input type="text" md-maxlength="30" required="" md-no-asterisk="" name="roomNo" ng-value="roomDTO.roomNo" ng-model="roomDTO.roomNo">
</md-input-container>
<md-input-container class="md-block">
<label>Availability</label>
<input type="text" md-maxlength="50" required="" md-no-asterisk="" name="availability" ng-value="roomDTO.isAvailable" ng-model="roomDTO.isAvailable">
<md-input-container class="md-block" ng-init="controller.getAllFacilitiesForRoom()">
<lable> Room Facility</lable>
<md-chips class="custom-chips" ng-model="controller.facilityList" readonly="controller.readonly" md-removable="controller.removable" >
<input type="hidden" ng-model={{$chip.id}}>
<md-chip-template>
<strong>{{$chip.facilityName}}</strong>
</md-chip-template></md-chips>
</md-input-container>
<div align="right">
<md-input-container class="md-block">
<div layout="row">
<md-button type="reset" md-no-ink class="md-warn" >➰ Reset </md-button>
<md-button type="submit" md-no-ink class="md-primary">✔Create </md-button>
</div>
</md-input-container>
</div>
</div>
</form>
</div>
</div>
</div>
答案 0 :(得分:0)
有几种方法可以解决这个问题。在这里,我提到了从控制器中捕获所选芯片的简单和通用方法。
<强> yourHTMLPage.html 强>
<md-input-container class="md-block" ng-init="yourCtrl.getValueList()">
<md-chips
multiple="true" md-no-cache="true" readonly="readOnly" ng-model="yourCtrl.bindValue"
md-on-select="yourCtrl.selectedChips($chip)"
md-on-remove="yourCtrl.deleteChips($chip)" >
<md-chip-template>
<strong >{{$chip.para1}}</strong>
</md-chip-template>
</md-input-container>
<强> controller.js 强>
vm.selectedChips=function(chip){
console.log(chip);
vm.yourDTO.youtList.push(chip);
// vm.yourList.push(chip);
};
vm.deleteChips=function(chip){
console.log(chip);
vm.deleteFaciltyList.push(chip);
};