Get selected option from select with angular JS and ionic

ben

I have some issues with select on angular Js, I searched a lot and found some solutions but not working.

I have a Json Structured like that generated from my service.php

[
    {
        "Name": "Name1",
        "Variante": [
            {
                "Prix": "79.00",
                "Name": "20 Piéces"
            }
        ],
        "Description": "",
        "main_image": "images/products/DSC_0192.jpg"
    },
    {
        "Name": "NAME2",
        "Variante": [
            {
                "Prix": "39.00",
                "Name": "250g"
            },
            {
                "Prix": "60.00",
                "Name": "500g"
            }
        ],
    "Description": "",
    "main_image": "images/products/DSC_0125.jpg"
    }
]

Here is my controller.js

.controller('productsCtrl', function($scope, $http, $stateParams) {
    $http.get('service.php')
    .success(function (response) {
        $scope.products = response;
    });
});

Here is my products.html

<ion-view view-title="Products">
    <ion-content>
        <ion-list>
            <ion-item style="background-image: url({{product.main_image}})" 
            ng-repeat="product in products" class="productListItem">
                <h2 class="h2Name">{{product.Name}}</h2>

                <button class="button button-balanced button-right">
                    <i class="icon ion-ios-cart"></i>
                </button>

                <select class="Variantes" 
                    ng-if="product.Variante.length > 1" 
                    ng-model="selectedItem"
                    ng-options="variant.Name for variant in product.Variante">
                </select>

                <h2 class="Variantes" ng-if="product.Variante.length == 1">
                    {{product.Variante[0].Name}}
                </h2>
                <h2 class="h2Price" ng-if="product.Variante.length > 1">
                    {{selectedItem.Prix}}
                </h2>
                <h2 class="h2Price" ng-if="product.Variante.length == 1">
                    {{product.Variante[0].Prix}}
                </h2>

            </ion-item>
        </ion-list>
    </ion-content>
</ion-view>

If I have more than one VarianteI want to be able to change the price (Prix) value when I change the select box. But it doesn't work.

Any help needed !!

Thanks

Diana R

The issue you have is due to the ng-if. It creates a separate scope, use ng-show instead cause it uses the same scope and your code should work perfectly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get selected option in angular <select>

From Dev

Need to get selected option from Select component

From Dev

Get selected option value from specific select

From Dev

Need to get selected option from Select component

From Dev

With webdriver.js, how to get the selected option of a <select>?

From Dev

How to get attribute from selected option of select in jQuery?

From Dev

jsoup - get selected option from html select's options

From Dev

How to get all selected values from multiple select option?

From Dev

Get optGroup id from selected option in select2

From Dev

Get selected option from the tag <select> in php to use on if

From Dev

How to get the selected option value from select inside div

From Dev

ionic2 show input field when other option is selected from select box

From Dev

Get the text from a selected option

From Dev

Get text from selected option

From Dev

setting selected option on select in angular ngoptions

From Dev

Clear selected option in ui-select angular

From Dev

setting selected option on select in angular ngoptions

From Dev

Get the option value of the select tag on load in Angular JS

From Java

jquery select change event get selected option

From Dev

Select2 Get selected option data

From Dev

How to get the option value of selected in Select dropdown

From Dev

Angular 2 - how to get value from select / option

From Dev

Select option selected an not selected

From Dev

Python selenium select option from angular js drop down

From Dev

Get selected object in angular select

From Dev

AngularJS and select2 from Angular-UI: Selected option different from what user picks

From Dev

ion-select not showing selected option with FormBuilder (Ionic 3)

From Dev

Remove selected option from another select box

From Dev

Render select Tag from jQuery Ajax , then get the value from selected option

Related Related

  1. 1

    How to get selected option in angular <select>

  2. 2

    Need to get selected option from Select component

  3. 3

    Get selected option value from specific select

  4. 4

    Need to get selected option from Select component

  5. 5

    With webdriver.js, how to get the selected option of a <select>?

  6. 6

    How to get attribute from selected option of select in jQuery?

  7. 7

    jsoup - get selected option from html select's options

  8. 8

    How to get all selected values from multiple select option?

  9. 9

    Get optGroup id from selected option in select2

  10. 10

    Get selected option from the tag <select> in php to use on if

  11. 11

    How to get the selected option value from select inside div

  12. 12

    ionic2 show input field when other option is selected from select box

  13. 13

    Get the text from a selected option

  14. 14

    Get text from selected option

  15. 15

    setting selected option on select in angular ngoptions

  16. 16

    Clear selected option in ui-select angular

  17. 17

    setting selected option on select in angular ngoptions

  18. 18

    Get the option value of the select tag on load in Angular JS

  19. 19

    jquery select change event get selected option

  20. 20

    Select2 Get selected option data

  21. 21

    How to get the option value of selected in Select dropdown

  22. 22

    Angular 2 - how to get value from select / option

  23. 23

    Select option selected an not selected

  24. 24

    Python selenium select option from angular js drop down

  25. 25

    Get selected object in angular select

  26. 26

    AngularJS and select2 from Angular-UI: Selected option different from what user picks

  27. 27

    ion-select not showing selected option with FormBuilder (Ionic 3)

  28. 28

    Remove selected option from another select box

  29. 29

    Render select Tag from jQuery Ajax , then get the value from selected option

HotTag

Archive