I'm currently working on implementing an add more field feature in angularjs. Here is the code that I am using:
Javascript
<script>
function FruitsController($scope){
var div = 'Apple';
$scope.fruits=[];
$scope.addFruit=function(){
$scope.fruits.push(div);
}
}
<script>
HTML
<ul><li ng-repeat="fruit in fruits">{{fruit}}</li></ul>
<button ng-click="addFruit()">Add</button>
The above code successfully appends the 'Apple' string in the body. However, my goal is to append an input type text field instead of a string. I have tried the following script, but it does not work as expected.
<script>
function FruitsController($scope){
var div = '<input type="text">';
$scope.fruits=[];
$scope.addFruit=function(){
$scope.fruits.push(div);
}
}
<script>
I am aware that my current approach is incorrect. If you have any ideas or suggestions on how to add an input type in AngularJS, please share them with me.