我使用模态实例打开一个带有 Controller 的模态,该 Controller 定义在主 Controller 中。
var helloControllers = angular.module('helloControllers', []);
helloControllers.controller('ScheduleUpdateCtrl', ['$scope','$routeParams', '$http','$modal',
function($scope,$routeParams, $http, $modal) {
/*--------lines of code-------------*/
$scope.setting=function(){
var modalInstance = $modal.open({
templateUrl: 'ScheduleSettings/ScheduleSettings.html',
controller: ScheduleSettingsCtrl,
/*--- lines of code--------------*/
var ScheduleSettingsCtrl = function ($scope, $modalInstance,$filter,scheduleId,scheduleName,grouplist,devicelist,secondtime)
现在我需要对列表框使用过滤器以排除包含在另一个列表框中的项目
<select size=9 ng-model="deviceselected" ng-options="de as de.DEVICE_NAME for de in deviceAllList|exclude"></select>
<select size=9 ng-model="deviceavailable" ng-options="de as de.DEVICE_NAME for de in deviceList"></select>
类似于:
filter('exclude',function(){
return function(array){
var out=[];
alert('!');
for(var i=0;i<array.length;i++){
alert(array[i].GROUP_ID);
if(groupList.map(function(e) { return e.GROUP_NAME; }).indexOf(array[i].GROUP_NAME)==-1)
out.push(array[i]);
}
return out;
};
但我不知道将这些行放在哪里或在 html 中使用它。我一无所知,因此非常感谢帮助演示。
更多详情
更多问题: 过滤器定义应该属于哪里?我试过了
helloControllers.filter('exclude',function(){
如何测试过滤器调用是否有效/未定义?我收到了这个错误。
Error: [$injector:unpr] Unknown provider: excludeFilterFilterProvider <- excludeFilterFilter
最佳答案
试试这个:就像我们在其他一些 html 元素中使用过滤器一样简单。与 |
的方式相同。您可以在 ng-options
中应用过滤器
<select size=9 ng-model="deviceselected" ng-options="de as de.DEVICE_NAME for de in deviceAllList | exclude"></select>
<select size=9 ng-model="deviceavailable" ng-options="de as de.DEVICE_NAME for de in deviceList | exclude"></select>
关于javascript - 如何在模态实例中使用过滤器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29359504/