Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用Angular 1.6/MVC 4.6/UI网格更正$injector:unpr错误_Javascript_Angularjs_Model View Controller - Fatal编程技术网

Javascript 如何使用Angular 1.6/MVC 4.6/UI网格更正$injector:unpr错误

Javascript 如何使用Angular 1.6/MVC 4.6/UI网格更正$injector:unpr错误,javascript,angularjs,model-view-controller,Javascript,Angularjs,Model View Controller,我正在使用Angular 1.6/MVC4.6/E.F 6.0开发一个Web应用程序。我还加了一句。它工作得很好。我正在尝试创建一个自定义过滤器,如。我的目标是创建与“Age”相同的自定义过滤器。它在本地运行,但在我发布WebApp时不起作用。我有两个错误: Possibly unhandled rejection: canceled Error: [$injector:unpr] http://errors.angularjs.org/1.6.2/$injector/unpr?p0=nProv

我正在使用Angular 1.6/MVC4.6/E.F 6.0开发一个Web应用程序。我还加了一句。它工作得很好。我正在尝试创建一个自定义过滤器,如。我的目标是创建与“Age”相同的自定义过滤器。它在本地运行,但在我发布WebApp时不起作用。我有两个错误:

Possibly unhandled rejection: canceled
Error: [$injector:unpr] http://errors.angularjs.org/1.6.2/$injector/unpr?p0=nProvider%20%3C-%20n%20%3C-%20myCustomModalCtrl
我很确定它与我为这个定制过滤器添加的控制器/指令有关。我已经读过了,但我不知道如何纠正这个错误,以及为什么它只能在本地工作

JS

var PrintersApp=angular.module('PrintersApp',['ui.grid','ui.grid.pagination','ui.grid.selection','ui.grid.exporter','ui.grid.moveColumns','ui.grid.autoResize']);
var Now=新日期();
PrintersApp.controller('PrintersController',['$scope','$http','$filter','uiGridConstants',',
函数($scope、$http、$filter、uiGridConstants){
var存储=$scope;
$scope.highlightFilteredHeader=函数(行、行渲染索引、列、列渲染索引){
if(列过滤器[0]。术语){
返回“头过滤”;
}否则{
返回“”;
}
};
var ExportDate=$filter('date')(现在是“MM dd yyyy”);
$scope.gridOptions={
启用筛选:正确,
分页页面大小:[25,50,75],
分页页面大小:25,
enableGridMenu:true,
enableSelectAll:false,
exportermanuff:false,
exporterCsvFilename:ExportDate+'-PrintersDataExport.csv',
exporterCsvLinkElement:angular.element(document.queryselectoral(“.custom csv link location”),
onRegisterApi:函数(gridApi){
$scope.gridApi=gridApi;
},
onRegisterApi:函数(gridApi){
$scope.gridApi=gridApi;
},
columnDefs:[
{字段:'Date',enableFiltering:false,enableColumnMenu:false,enableSorting:false,width:160},
{字段:'User',headerCellClass:$scope.highlightFilteredHeader,enableHidden:false,宽度:160},
{字段:'Pc',headerCellClass:$scope.highlightFilteredHeader,enableHidden:false,宽度:120},
{字段:'PrinterSrv',enableFiltering:$scope.highlightFilteredHeader,EnableHidden:false,},
{
字段:“PrinterName”,
filterHeaderTemplate:“”,
宽度:320,
},
{
字段:“默认”,筛选器:{
类型:uiGridConstants.filter.SELECT,
选择选项:[{value:'true',label:'true'},{value:'false',label:'false'},]
},
headerCellClass:$scope.highlightFilteredHeader,enableColumnMenu:false,enableSorting:false,宽度:150
},
]
};
$http.get(“/AuditPrinters/GetAuditPrintersData”)
.然后(功能(响应){
var datatest=response.data;
forEach(函数addDates(行、索引){
时间戳=(row.Date).replace('/Date(','').replace(')/','')
行日期=$filter('Date')(时间戳,“MM/dd/yyyy HH:MM:ss”);
});
$scope.gridOptions.data=datatest;
},函数(err){
警报(“Erreur”+rr);
});
$scope.toggleFiltering=函数(){
$scope.gridOptions.enableFiltering=!$scope.gridOptions.enableFiltering;
$scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
};
}])
PrinterApp.directive('myCustomDropdown',函数(){
返回{
模板:“”
};
})
PrinterApp.controller('myCustomModalCtrl',函数($scope、$compile、$timeout){
var$elm;
$scope.showPrinterNameModal=函数(){
$scope.listofpropris=[];
$scope.col.grid.appScope.gridOptions.data.forEach(函数(行){
if($scope.listofpropris.indexOf(row.PrinterName)=-1){
$scope.listofpropris.push(row.PrinterName);
}
});
$scope.listofpropris.sort();
$scope.gridOptions={
数据:[],
EnableColumn菜单:false,
onRegisterApi:函数(gridApi){
$scope.gridApi=gridApi;
if($scope.colFilter&&$scope.colFilter.listTerm){
$timeout(函数(){
$scope.colFilter.listTerm.forEach(函数(PrinterName){
var entities=$scope.gridOptions.data.filter(函数(行){
返回row.PrinterName==PrinterName;
}); 
如果(entities.length>0){
$scope.gridApi.selection.selectRow(实体[0]);
}
});
});
}
} 
};
$scope.listofpropris.forEach(函数(PrinterName){
$scope.gridOptions.data.push({PrinterName:PrinterName});
});
var html='Filter AgesFilter';
$elm=angular.element(html);
元素(document.body).prepend($elm);
$compile($elm)($scope);
};
$scope.close=函数(){
var printersname=$scope.gridApi.selection.getSelectedRows();
$scope.colFilter.listTerm=[];
PrinterName.forEach(函数(PrinterName){
$scope.colFilter.listTerm.push(PrinterName.PrinterName);
});
$scope.colFilter.term=$scope.colFilter.listTerm.join(',');
$scope.colFilter.condition=newregexp($scope.colFilter.listTerm.join(“|”);
如果($elm){
$elm.remove();
}
};
})
PrinterApp.directive('myCustomModal',函数(){
返回{
模板:{{colFilter.term}},
控制器:“myCustomModalCtrl”,
};
});

不确定这是否有帮助,但您的问题可能与
myCustomModalCtrl
控制器的声明有关。与其他声明相比,此声明缺少i的完整限定声明
var PrintersApp = angular.module('PrintersApp', ['ui.grid', 'ui.grid.pagination', 'ui.grid.selection', 'ui.grid.exporter', 'ui.grid.moveColumns', 'ui.grid.autoResize']);

var Now = new Date();

PrintersApp.controller('PrintersController', ['$scope', '$http', '$filter', 'uiGridConstants',
    function ($scope, $http, $filter, uiGridConstants) {
        var store = $scope;
        $scope.highlightFilteredHeader = function (row, rowRenderIndex, col, colRenderIndex) {
            if (col.filters[0].term) {
                return 'header-filtered';
            } else {
                return '';
            }
        };
        var ExportDate = $filter('date')(Now, "MM-dd-yyyy");
        $scope.gridOptions = {
            enableFiltering: true,
            paginationPageSizes: [25, 50, 75],
            paginationPageSize: 25,
            enableGridMenu: true,
            enableSelectAll: false,
            exporterMenuPdf: false,
            exporterCsvFilename: ExportDate + '-PrintersDataExport.csv',
            exporterCsvLinkElement: angular.element(document.querySelectorAll(".custom-csv-link-location")),
            onRegisterApi: function (gridApi) {
                $scope.gridApi = gridApi;
            },
            onRegisterApi: function (gridApi) {
                $scope.gridApi = gridApi;
            },
            columnDefs: [
              { field: 'Date', enableFiltering: false, enableColumnMenu: false, enableSorting: false, width: 160 },
              { field: 'User', headerCellClass: $scope.highlightFilteredHeader, enableHiding: false, width: 160 },
              { field: 'Pc', headerCellClass: $scope.highlightFilteredHeader, enableHiding: false, width: 120 },
              { field: 'PrinterSrv', enableFiltering: $scope.highlightFilteredHeader, enableHiding: false, },
              {
                  field: 'PrinterName',
                  filterHeaderTemplate: '<div class="ui-grid-filter-container" ng-repeat="colFilter in col.filters"><div my-custom-modal></div></div>',
                  width: 320,
              },
              {
                  field: 'Default', filter: {
                      type: uiGridConstants.filter.SELECT,
                      selectOptions: [{ value: 'true', label: 'true' }, { value: 'false', label: 'false' }, ]
                  },
                  headerCellClass: $scope.highlightFilteredHeader, enableColumnMenu: false, enableSorting: false, width: 150
              },
            ]
        };

        $http.get('/AuditPrinters/GetAuditPrintersData')
        .then(function (response) {
            var datatest = response.data;
            datatest.forEach(function addDates(row, index) {
                TimeStamp = (row.Date).replace('/Date(', '').replace(')/', '')
                row.Date = $filter('date')(TimeStamp, "MM/dd/yyyy HH:mm:ss");
            });
            $scope.gridOptions.data = datatest;
        }, function (err) {
            alert("Erreur" + rr);
        });
        $scope.toggleFiltering = function () {
            $scope.gridOptions.enableFiltering = !$scope.gridOptions.enableFiltering;
            $scope.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN);
        };
    }])

PrintersApp.directive('myCustomDropdown', function () {
  return {
    template: '<select class="form-control" ng-model="colFilter.term" ng-options="option.id as option.value for option in colFilter.options"></select>'
  };
})

PrintersApp.controller('myCustomModalCtrl', function ($scope, $compile, $timeout) {
  var $elm;
  $scope.showPrintersNameModal = function() {
    $scope.listOfPrinters = [];

    $scope.col.grid.appScope.gridOptions.data.forEach( function ( row ) {
        if ($scope.listOfPrinters.indexOf(row.PrinterName) === -1) {
            $scope.listOfPrinters.push(row.PrinterName);
      }
    });
    $scope.listOfPrinters.sort();
    $scope.gridOptions = { 
      data: [],
      enableColumnMenus: false,
      onRegisterApi: function( gridApi) {
        $scope.gridApi = gridApi;

        if ( $scope.colFilter && $scope.colFilter.listTerm ){
          $timeout(function() {
              $scope.colFilter.listTerm.forEach(function (PrinterName) {
              var entities = $scope.gridOptions.data.filter( function( row ) {
                  return row.PrinterName === PrinterName;
              }); 

              if( entities.length > 0 ) {
                $scope.gridApi.selection.selectRow(entities[0]);
              }
            });
          });
        }
      } 
    };

    $scope.listOfPrinters.forEach(function (PrinterName) {
        $scope.gridOptions.data.push({ PrinterName: PrinterName });
    });
    var html = '<div class="modal" ng-style="{display: \'block\'}"><div class="modal-dialog"><div class="modal-content"><div class="modal-header">Filter Ages</div><div class="modal-body"><div id="grid1" ui-grid="gridOptions" ui-grid-selection class="modalGrid"></div></div><div class="modal-footer"><button id="buttonClose" class="btn btn-primary" ng-click="close()">Filter</button></div></div></div></div>';
    $elm = angular.element(html);
    angular.element(document.body).prepend($elm);
    $compile($elm)($scope);
  };

  $scope.close = function() {
    var printersname = $scope.gridApi.selection.getSelectedRows();
    $scope.colFilter.listTerm = [];
    printersname.forEach(function (PrinterName) {
        $scope.colFilter.listTerm.push(PrinterName.PrinterName);
    });

    $scope.colFilter.term = $scope.colFilter.listTerm.join(', ');
    $scope.colFilter.condition = new RegExp($scope.colFilter.listTerm.join('|'));

    if ($elm) {
      $elm.remove();
    }
  };
})

PrintersApp.directive('myCustomModal', function () {
  return {
      template: '<label>{{colFilter.term}}</label><button ng-click="showPrintersNameModal()">...</button>',
    controller: 'myCustomModalCtrl',
  };
});
PrintersApp.controller('myCustomModalCtrl', function ($scope, $compile, $timeout) { [..] });
PrintersApp.controller('myCustomModalCtrl', ['$scope', '$compile', 
'$timeout', function ($scope, $compile, $timeout) { [..] }]);