How to retrieve dynamic parameters with AngularJS

85 views Asked by At

I can't retrieve the parameters with ng-submit in a dynamic form submit.

.

Screenshot:

help-me--with--get-parameters-in-form

Show code:

(function() {
    'use strict';

    angular.module('starter.controllers')
        .controller('MessagesCtrl', msgs);

    function msgs() {
        console.log('Loading MessagesCtrl!');

        var vm = this;

        vm.doMessage = function(_form) {
            if (_form.$valid) {
                console.log(_form);

                // Who get parameters dynamic to POST?
            }
        };
    };

})();

Html form

<form name="submitForm" no-validate="" ng-submit="vm.doMessage(submitForm)">
    <div class="responsive-grid-break list list-inset padding-1">

        <h1>Enviar uma mensagem</h1>

        <label class="item item-input">
            <span class="input-label">For</span>

            <div class="item-input">
                <i class="icon ion-search placeholder-icon"></i>

                <input type="search" name="search" ng-model="msg.search" placeholder="..." />
            </div>
        </label>

        <label class="item item-input">
            <span class="input-label">Message</span>

            <div class="separator item-input">
                <textarea name="msgtext" ng-model="msg.text" placeholder="This message."></textarea>
            </div>
        </label>

        <div class="list list-inset">
            <div class="padding">
                <button class="button button-block button-royal" type="submit">Send</button>
            </div>
        </div>

    </div>
</form>
1

There are 1 answers

4
devqon On

Usually, you use Angular to bind inputs to models, and you have access to those models from within your controller:

<div>
    <form name="myForm" ng-submit="vm.doMessage()">
        <input type="text" ng-model="formData.name" />
        <input type="date" ng-model="formData.date" />
        <input type="submit" value="Submit" />
    </form>
</div>

and controller:

function msgs() {
    console.log('Loading MessagesCtrl!');

    var vm = this;

    vm.doMessage = function() {

        if (vm.myForm.$valid) {
            var name = vm.formData.name;
            var date = vm.formData.date;
        }
    }
};