0
所以我发现自己有点阻碍从角度的下拉选项中获取值,以便为我的postgreSQL数据库创建两个特定用户角色之一。角度下拉选项值数据库中的用户角色的登录数据对象
我有很多的投入(几个互斥下拉),用于创建用户如: 1名 2.密码 3.电子邮件 等..
所有很容易传递到用户对象在我的角度控制器内使用ng-model来引用它们。我试图用我的表单实现的是我的选择下拉列表中的每个选项都将特定值记录到我的用户对象中的角色的关键字,因此我可以将它存储到“角色”字段中的特定记录。
HTML SNIPPIT:
<form name="createAccount" ng-submit="create(this)">
<select ng-model="showRole" class="form-control" ng-options="role.abbreviation as role.name for role in roles">
<option value="">Choose One</option>
</select>
<div ng-switch="showRole">
<div ng-switch-when="agt">
<div>
<label for="firstName">First Name</label>
<input type="text" ng-model="createAccount.firstName">
</div>
<div>
<label for="lastName">Last Name</label>
<input type="text" ng-model="createAccount.lastName">
</div>
<div>
<label for="email">E-mail</label>
<input type="e-mail" ng-model="createAccount.email">
</div>
<div>
<label for="company">Agency</label>
<input type="text" ng-model="createAccount.company">
</div>
<div>
<label for="createAccount-username">Username</label>
<input type="text" ng-model="createAccount.username">
</div>
<div>
<label for="createAccount-password">Password</label>
<input type="password" ng-model="createAccount.password">
</div>
<div>
<label for="createAccount-passwordConfirm">Password Confirm</label>
<input type="password" ng-model="createAccount.passwordConfirm">
</div>
</div>
<div ng-switch-when="pmt">
<div>
<label for="firstName">First Name</label>
<input type="text" ng-model="createAccount.firstName">
</div>
<div>
<label for="lastName">Last Name</label>
<input type="text" ng-model="createAccount.lastName">
</div>
<div>
<label for="email">E-mail</label>
<input type="e-mail" ng-model="createAccount.email">
</div>
<div>
<label for="company">Venue</label>
<input type="text" ng-model="createAccount.company">
</div>
<div>
<label for="createAccount-username">Username</label>
<input type="text" ng-model="createAccount.username">
</div>
<div>
<label for="createAccount-password">Password</label>
<input type="password" ng-model="createAccount.password">
</div>
<div>
<label for="createAccount-passwordConfirm">Password Confirm</label>
<input type="password" ng-model="createAccount.passwordConfirm">
</div>
</div>
<div>
<button>Create Account</button>
</div>
和角度控制器:
(function(){
var LoginController = function ($scope, $http) {
$scope.pageID = "Login/Register Page";
$scope.create = (form) => {
console.log('create form submitted');
const user = {
firstName: form.createAccount.firstName,
lastName: form.createAccount.lastName,
email: form.createAccount.email,
company: form.createAccount.company,
username: form.createAccount.username,
password: form.createAccount.password,
}
$http.post('/users/create', user)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.log(err);
})
}
$scope.loginSubmitted = (form) => {
console.log('login form submitted');
}
$scope.roles = [{ abbreviation: 'agt', name: "Agent"},{abbreviation: 'pmt', name: "Promoter"}];
this.setTab = function(setTab) {
this.tab = setTab;
};
this.isSelected = function(checkTab) {
return this.tab === checkTab;
};
this.notSelected = function(checkTab) {
return !(this.isSelected(checkTab));
};
this.getTab = function() {
return this.tab;
};
this.setIsDefault = function() {
this.isDefault = true;
};
this.getIsDefault = function() {
return this.isDefault;
};
}
angular.module('avp')
.controller('LoginController', LoginController);
LoginController.$inject = ['$scope', '$http'];
}())