How to upload this created data to an edit screen

Asked

Viewed 112 times

1

Next, I have this sign-up screen where clicking the "+" button will add text type inputs (as an attachment code) My problem is that this creation is dynamic, one can add either 1, or 2,3,4.. or N. I’m going to save that data, and I need when it comes to editing, to be able to assemble that same structure. That is, it will load all the text inputs created on the addition screen. I don’t know how to get this information out dynamically. I’m applying v1 angular to the project, I’m using it to integrate with the backend. Then I’d like a more focused, angled solution. There’s a way to do it?

1 answer

0

Set 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 inputs. For this, you need to create html dynamically by being an array that will have a dynamic counter, and then enter the $compile, documentation here: https://docs.angularjs.org/api/ng/service/$Compile

Basically it 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 var input is rendered. Don’t forget to increase the counter at the end: counter++

Browser other questions tagged

You are not signed in. Login or sign up in order to post.