2017-05-12 6 views
-1

私の現在のコード:AngularJSのユーザー登録に選択メニューを使用するにはどうすればいいですか?

<select ng-model="user.userType" ng-required="true" class="form-control"> 
    <option value="pharmacist">Pharmacist</option> 
    <option value="chief_pharmacist">Chief Pharmacist</option> 
    <option value="doctor">Doctor</option>  
</select> 

//sample code 

私は選択メニューにあるように、データベースに選択された値を渡すために3つのユーザータイプを必要とします。

+1

達成したいことは?その働き:http://plnkr.co/edit/YzHPRKUMpnwGPySWJZwg?p=preview –

答えて

0

このように、あなたのビューで角度コントローラを使用する必要があります。

var myApp = angular.module('myApp', []); 
 

 
myApp.controller('MyController', ['$scope', function($scope){ 
 
    $scope.user = {}; 
 
    
 
    $scope.registerUser = function(){ 
 
    alert($scope.user.userType); 
 
    }; 
 
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 

 
<div ng-app="myApp"> 
 
    <div ng-controller="MyController"> 
 
    <select ng-model="user.userType" ng-required="true" class="form-control"> 
 
       <option value="pharmacist">Pharmacist</option> 
 
       <option value="chief_pharmacist">Chief Pharmacist</option> 
 
       <option value="doctor">Doctor</option> 
 

 
    </select> 
 
    <button ng-click="registerUser()">register</button> 
 
    </div> 
 
</div>

0

また、これは(私がidではなくnameを渡す好む)あなたが渡すべき値述べた、私はこれを達成するための2つの方法が記載されているしている、あなたを助けるかもしれない:

Plnkr

関連する問題