How to load this data created in an edit screen

1

Next, I have this registration screen where clicking the "+" button will add text type inputs (according to the attached code) My problem is that this creation is dynamic, the person can add either 1, when 2,3,4..or it's N. I'm going to save this data and I need to edit the same structure. That is, it will load all the text inputs created in the addition screen. I do not know how to do bring this information dynamically. I'm applying angular v1 in the project, I'm using to do integration with the backend. So I would like a more focused pro angular solution. Is there a way to do it?

    
asked by anonymous 12.07.2017 / 16:37

1 answer

0

Define a variable that will store the values in the controller and a counter:

$scope.x = [];
$scope.counter = 0;

Now you need to put ng-model on the inputs. For this, you need to dynamically create the html because it is an array that will have a dynamic counter, and then enter the $compile , documentation here: link $ compile

It basically works like this:

// cria o input
var input = '<div class="itens"><div id="radios"><input type="radio" disabled style="vertical-align: text-bottom;" value="teste" name="data"><input type="text" value="" class="form-control radio-alinha text" placeholder="Adicionar Alternativa" ng-model="x[' + $scope.counter + ']"><a href="#" class="del"><span class= "glyphicon glyphicon-trash"></span></a></div></div>';
//compila e coloca no escopo
var compile = $compile(input)($scope);

Then the var input is rendered. Do not forget to increase the counter at the end: counter++

    
12.07.2017 / 17:49