我已經發布了我的代碼。我想從我的選項中刪除Kanhu
。如何在AngularJS中刪除動態創建的下拉選項?
查看工作示例。
var myApp = angular.module('myApp',[]);
function myCtrl ($scope) {
$scope.userProfiles = [
{id: 10, name: 'Chinmay'},
{id: 27, name: 'Sanjib'},
{id: 35, name: 'Kanhu'},
{id: 38, name: 'Pradeepta'},
{id: 39, name: 'Debsish'},
];
$scope.selectedUserProfile= $scope.userProfiles[1].id;
$scope.existingId = 35;
};
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
Name
<select id="requestorSite" ng-model="selectedUserProfile" ng-options="userProfile.id as userProfile.name for userProfile in userProfiles">
</select>
<br/>
</div>
這裏是5名在下拉列表中來,但我想刪除從我的下拉選項kanhu
。你能說我怎麼刪除它嗎?
我試過使用過濾器userProfile.id as userProfile.name for userProfile in userProfiles | filter:{id: !existingId}
這一個不工作。
試試這個ANS:http://stackoverflow.com/questions/24761281/hiding-an-option-in-ng - 選項 –