How to send data using form on ionic


#1

hi people I am a new using ionic,
I need to send data using form but not working check my code please

<!-- show modal -->
<script id="contact-modal.html" type="text/ng-template">
    <div class="modal">
        <ion-header-bar>
            <button type="reset" class="button button-clear" ng-click="closeModal()">
                <i class="ion ion-close"></i>
            </button>
        </ion-header-bar>
        <ion-content>
            <form ng-submit="saveCart(product)">
                <div class="row">
                    <div class="list">
                        <div class="col-50 zupa_left zupa_img_pro">
                            <img ng-src="{{img}}" alt="zupa"/>
                            <p>{{description}}</p>
                            <p>{{price}} Bs.</p>
                        </div>
                        <div class="col-50 zupa_left zupa_spin">
                           <!-- <ng-touch-spin ng-model="product.cant"  initval="0"  step="1">
                            </ng-touch-spin>-->
                            <input type="text" initval="0" step="1" ng-model="product.cant" ng-touch-spin>
                        </div>
                        <input type="hidden" value="{{price}}" ng-model="product.price" />
                        <input type="hidden" value="{{id_item}}" ng-model="product.iditem" />

                    </div>
                </div>
                <div class="row">
                    <div class="zupa_btn_cart">
                        <div class="text-center">
                            <button type="reset" class="button button-assertive" ng-click="closeModal()"><i class="ion ion-close"></i></button>
                            <button type="submit" class="button  button-positive"><i class="ion ion-ios-cart"></i></button>
                        </div>
                    </div>
                </div>
            </form>


        </ion-content>
    </div>
</script>

I need to send data of (product.cant, product.price, product.iditem) and this is my controller code

$scope.saveCart = function(product){
$scope.products = {id_item:product.iditem, val:product.cant, price:product.price};
console.log(product.cant);
}
whe my controller recived (var product) this show me an error of the ( TypeError: Cannot read property ‘cant’ of undefined ) and the semething the other var.

Please help me wich is my error


#2

Did you define product in your controller as a scope variable, something like:

$scope.product = { id_item: 1, img: 'path/to/image', description: 'A product', price: 23.45, .... };

If not, the saveCart function simply gets an undefined object which has no properties at all (which would explain the message ‘cannot read property x of undefined’).