javascript - AngularJS - Form with Select element to get Id from another object -


i have 2 tables "category" , "publication" 1 many relationship.

category: id, name, description

publication: id, title, content, category_id

and need category id through select element , put in category_id field.

publication form:

<form>   <input type="text" ng-model="publication.title" placeholder="title" />   <input type="text" ng-model="publication.content" placeholder="content" />   <!-- here problem because can list categories can't category id , put in category_id field -->   <div ng-init="categories()">     <select class="form-control" ng-model="category" ng-options="category.name category in categories">         <option value="">-- select category --</option>     </select>    </div> </form> 

this controller categories:

$scope.categories = function() {     $http(             {                 method : 'get',                 url : '/prodemo/category'             }).success(                     function(data, status, headers, config) {                         $scope.categories = data;             }).error(                     function(data, status, headers, config) {             }); }; 

how can it?

like below hidden field can that

    <form>       <input type="text" ng-model="publication.title" placeholder="title" />       <input type="text" ng-model="publication.content" placeholder="content" />       <input type="hidden" ng-model="publication.category_id = category.id" />        <div ng-init="categories()">         <select class="form-control" ng-model="category" ng-options="category.name category in categories">             <option value="">-- select category --</option>         </select>        </div>     </form> 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -