Tsila
April 29, 2017, 10:30am
#1
I turn to you for a small flaw that I have. I used modal-select to select an item from a list. The element I need for the query is the id of the element. What is operational, with this code
<div class="item item-body">
<a class="button button-positive" modal-select="" ng-model="form.product" options="Product" option-property="id" modal-title="Select an product" has-search="true">
Select it (with search)
<div class="option">
{{option.name}}
</div>
</a>
<div class="item">
Product : {{form.product}}
</div>
</div>
But on display, client side, I would like to have the name of the element and not the id, because for now it is the id that appears in :
<div class="item">
Product : {{form.product}}
</div>
And even if I do form.product.name
I was inspired by this: CodePen
Here is a small diagram of what I would like as a result :
Thank you in advance for your answers
you can do like this
<a class="button button-positive" modal-select="" ng-model="form.product" options="Product" modal-title="Select an product" has-search="true">
Select it (with search)
<div class="option">
{{option.name}}
</div>
</a>
you get the one product object in form.product . In the saving time you can take id from form.product.id
Tsila
April 29, 2017, 1:51pm
#3
I will then need the id of the product in a search form, where this id in form.product will be in parameter.
<a class="button button-positive button-block" ng-click="search()">Search</a>
In my controller :
$scope.search = function () {
AppService.searchProduct($scope.form).then(function(response){
$scope.listProduct = response;
});
};
This is where I blocked ^^
Because if I use my search function, it will take in parameter the id and the name of the product
CiKay
April 29, 2017, 2:08pm
#4
Iām also trying to do the same thing for a while, with this ionic plugin.
If I rely on this example, I try to get the ID only to be able to use it in a form. Knowing that the product name will still be displayed in the form, but that the ID will be in parameter
Tsila
April 29, 2017, 5:22pm
#5
The solution :
$scope.search = function () {
var myform = angular.copy($scope.form);
myform.product = myform.product.id;
AppService.searchProduct(myform).then(function(response){
$scope.listProduct = response;
});
};
1 Like