2
I am making some forms with Angular and in some of the cases I need the person to put some information to save the foreign key, basic example:
Let’s assume the sale of a product and the invoice table in the database asks for the seller’s id, product and customer.
For this I put a datalist to facilitate the user and he can select exactly what he wants. And to list all the data available for the user to select I’m using an Angular directive called ng-repeat so I need to add a controller, problem is when I need another controller to list in the other datalist but the first controller already controls the whole rest of the application and all the datalists I add list the same thing as the first.
<div ng-controller="ClientesCtrl as clCtrl">
<section >
<form name="some">
<label> Cliente
<input type="text" list="dataList">
</label>
<datalist id="dataList">
<option ng-repeat="clientesSave in clCtrl.clientesSaves" value="{{clientesSave.id_cliente}}" ng-model="odCtrl.equipSave.id_cliente">{{clientesSave.nome}}</option>
</datalist>
</form>
</section>
</div>
<div ng-controller="EquipCtrl as eqCtrl">
<section ng-controller="EquipCtrl as eqCtrl">
<form name="some">
<label> Tipo de Equipamento
<input type="text" list="dataList" placeholder="selecione">
</label>
<datalist id="dataList">
<option ng-repeat="equipSave in eqCtrl.equipSaves" value="{{equipSave.id_tipo}}" ng-model="odCtrl.equipSave.id_tipo">{{equipSave.nome_equip}}</option>
</datalist>
</form>
</section>
</div>
I tried to make a Component but it still works, so I thought of two possible solutions but I don’t know if it’s good practice, first I would add back routes in the same controller, then it would be two or more get per controller commands just to give me information I want from another table, or else on the back itself I already do the searches I need, put all the necessary information on a route and add that route to the controller responsible for that form.
Or there’s some way I can isolate the first controller so it doesn’t affect the others?
Maybe this article will help you https://cursos.alura.com.br/forum/topico-work.
– Saymon