L
L
Lietorick2015-03-01 20:02:51
Angular
Lietorick, 2015-03-01 20:02:51

How to submit a select value in a form?

<form ng-submit="send_ticket()">
    <div class="modal-body">
        <div class="form-group">
            <label for="ticketSubject">Тема</label>
            <input class="form-control" type="text" ng-model="ticketData.subject" required id="ticketSubject">
        </div>
        <div class="form-group" ng-controller="ServicesCtrl">
            <label for="ticketService">Услуга</label>
            <select class="form-control" ng-model="ticketData.service" id="ticketService" ng-options="opt as opt.id for opt in services">
                <option value="">Выберите услугу</option>
            </select>
        </div>
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-white" ng-click="cancel()">Закрыть</button>
        <button type="submit" class="btn btn-primary">Отправить</button>
    </div>
</form>

controller('ServicesCtrl', function($scope, $http) {
    $http.get('/links/services')
        .success(function(data) {
            $scope.services = data;
        });
})

[
  {"id": "1", "desc": "Описание", "date": "Дата", "status": "success"},
  {"id": "2", "desc": "Описание", "date": "Дата", "status": "success"},
  {"id": "3", "desc": "Описание", "date": "Дата", "status": "success"},
  {"id": "4", "desc": "Описание", "date": "Дата", "status": "success"},
  {"id": "5", "desc": "Описание", "date": "Дата", "status": "success"}
]

$scope.send_ticket = function() {
        $http.post('http://example.com/example.php', $scope.ticketData)
    };

All element values ​​are sent to the form, how to send only id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Dedukhin, 2015-03-01
@Lietorick

Show the value of $scope.services and what should be sent in ticketData.service to the server? It feels like you don't want to send the whole opt object.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question