I want to know when I click a button I need to add the fields like input type and other things dynamically from dropdown.
Hi @Hanu1994,
Do you mean that, you have a dropdown with certain data in it. So once you click on any of the data inside dropdown then one input field will be created in the view?
Hi @Hanu1994,
Controller Code
$scope.textbox={};
$scope.textarea={};
var i=0,j=0;
$scope.addcomnponent =function(value){
if(value=='text'){
$scope.textbox[i]={
type:"text",
value:'text'
}
i++;
console.log('$scope.textbox',$scope.textbox);
}
if(value=='textarea'){
$scope.textarea[j]={
type:"text",
value:'textarea'
}
j++;
console.log('$scope.textarea',$scope.textarea);
}
}
$scope.comnponentreset=function(){
$scope.textbox={};
$scope.textarea={};
i=0;
j=0;
}
}
View code
<select ng-model="select" >
<option value="" >Select Component</option>
<option value="text"> Input </option>
<option value="textarea">Textarea</option>
</select>
<Button nog-click="addcomnponent (select)">Add</button>
<button ng-click="comnponentreset()">Reset</button>
<div ng-if="textbox" ng-repeat="text in textbox">
<input type="text.text" ng-model="text.value">
</div>
<div ng-if="textarea" ng-repeat="texta in textarea">
<textarea ng-model="texta.value">hello</textarea>
</div>
Please review this code. I have tried to provide you the code best out of my understanding.
Hope this will help you with your issue. If you find it worthy, then please mark it as a solution and you can also like the answer by clicking on the heart icon.