i am building a project where we have one url input tag, which have its respective url mappings which needs to accept only URL and a add button to repeat two input tags from below scenerio: url1 have urla -> urlb, urlc->urld, urle->urlf,....it has add button add as many as mappings. On save we need to send this json format to post API.
required json format : { url1: { urla : urlb, urlc : urld, urle : urlf,... }, url2:{ urlg : urlh, urli: url,..... },...... }
ISSUE : i m unable to get the required json format from my code. ` HTML
<div>
<input id="url" type="text" ng-model="">
</div>
<div id="maprow1" class="row mt-5" ng-repeat="(privateUrl, publicUrl) in urlMappings track by $index">
<input id="privateurl1" type="text" class="form-control input-text http-input" ng-model="urlMappings.privateUrl">
<input id="publicurl1" type="text" class="form-control input-text http-input" ng-model="urlMappings.publicUrl">
<div id="mappingmain1" class="col-md-1 pr-0 text-right">
<button id="btnaddmapping1" class="button-default button-m panel-heading-margin" type="button" ng-click="addUrlMapping();" ng-if="$last">
<i class="di-block icon-add icon20 mr-0 v-sub"></i>
</button>
<button class="button-default button-m panel-heading-margin" type="button" ng-if="!$last" ng-click="slideUpModal();">
<i class="icon16 icon-delete v-sub di-block mr-0"></i>
</button>
<div id="addview" class=" pull-right p-20" ng-show="!displayModal">
<span class="button-cancel" data-dismiss="modal">Cancel</span>
<button id="addmapping" class="button-m button-primary" type="button" ng-click="addDomain();">Save</button>
</div>
</div>
controller:
$scope.urlMappings = [];
$scope.addUrlMapping = function() {
{
$scope.domainUrl ='';
$scope.privateUrl = '';
$scope.publicUrl = '';
const privateUrl = $scope.privateUrl;
const domainUrl = $scope.domainUrl;
var newUrlMappingField = {
[privateUrl]: $scope.publicUrl
};
$scope.urlMappings = {
[domainUrl] : newUrlMappingField
} };
`
Via Active questions tagged javascript - Stack Overflow https://ift.tt/DKUaEm3
Comments
Post a Comment