2015-03-31 62 views
1

我使用模态实例打开一个模态,其中包含在主控制器内定义的控制器。如何在模态实例中使用过滤器

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 

回答

2

试试这个:因为我们使用的过滤器在一些其它的HTML element.Same方式与|您可以在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> 
+0

适用于此过滤器是非常容易的是,我曾尝试这一点,但列表框是空白的。有什么方法可以测试过滤器是否有效/未定义? – dtxd 2015-03-31 03:34:38

+0

我得到这个错误 错误:[$ injector:unpr]未知的提供者:excludeFilterFilterProvider < - excludeFilterFilter – dtxd 2015-03-31 04:24:15

+0

您是否注册过滤器在您的应用程序模块? – 2015-03-31 04:49:06

相关问题