问题描述
我使用AngularJS来填充我的选择选项的对象在我的控制器的阵列动态内容。我的对象有一个属性名为用户配置文件名
I am using AngularJS to populate my select options content dynamically from an array of objects in my controller. My objects has a property named userProfileName.
怎么会可能取消,我在上面得到的空白选项?
How would it be possible to remove the blank option that I am getting at the top?
另外,我要选择的第一个配置文件个人资料1 按默认值。如何才能做到这一点?
Also, I would want to select the first profile Profile 1 by default. How can this be done?
我的code的片段是在这里:
My Snippet of code is here:
<select id="requestorSite"
ng-model="selectedUserProfile"
ng-options="userProfile.userProfileName for userProfile in userProfiles"
ng-selected=""
class="form-control displayInlineBlock width40per marginLeft15">
</select>
我的控制器具有
$scope.userProfiles
由于对象的数组,每个对象都有的用户配置文件名属性。
下面是截图:
Below is the screen shot:
我想在上面删除空白选项,默认情况下也个人资料有1 选择的。
I would like to remove the blank option at the top and also have by default Profile 1 selected.
谢谢,
ANKIT
Thanks,Ankit
推荐答案
做到这一点:)
在你的控制器:
function myCtrl ($scope) {
$scope.userProfiles = [
{id: 10, name: 'Carton'},
{id: 27, name: 'Bernard'},
{id: 39, name: 'Julie'},
];
$scope.selectedUserProfile= $scope.userProfiles[0]; // Set by default the value "carton"
};
在你的页面:
<select id="requestorSite" ng-model="selectedUserProfile" ng-options="userProfile as userProfile.name for userProfile in userProfiles">
</select>
codePEN: HTTP://$c$cpen.io/anon/pen/qdOGVB
这篇关于角NG选项删除空白选项,并仅选择第一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!