2016-08-16 55 views
0

问题:我有一个模式屏幕来编辑应用程序中的列表数据。我使用哟发电机进行CRUD操作。在编辑视图中,我有一个模式,它有一个单独的控制器,我在控制器文件夹中有一个单独的文件。Meanjs中的角度用户界面模态控制器弹出

我是新的angularjs 1.我无法得到模式弹出。我的代码中是否有错误?

我在控制台中得到了以下错误。

angular.js:11706 Error: [$injector:unpr] Unknown provider: customerResolveProvider <- customerResolve <- CustomersController 

//列表customer.client.view.html

<section data-ng-controller= "CustomersController as customersCtrl"> 
    <div class="page-header"> 
    <h1>Customers</h1> 
    </div> 
    <!--Search bar--> 
    <div class="col-xs-12 col-sm-8"> 
    <div class="input-group input-group-lg"> 
     <input type="text" class="form-control" placeholder="Search for..." ng-model="searchText"> 
     <span class="input-group-btn"> 
     <button class="btn btn-default" type="button">Go!</button> 
     </span> 
    </div><!-- /input-group --> 
    </div> 
    <div class="row"> 
    <div class="col-xs-12 col-sm-4 text-center"> 
     <button type="button" class="btn btn-success text-center"> 
     <i class="glyphicon glyphicon-user"></i><br> 
     New Customer 
     </button> 
    </div> 
    </div> 

    <div class="list-group"> 
    <div class="col-xs-6 col-sm-4" data-ng-repeat="customer in vm.customers | filter:searchText"> 
     <a ng-click="customersCtrl.modalUpdate('lg', customer)" 
     class="list-group-item"> 
     <h4 class="cust-list text-center"> 
      <i class="glyphicon glyphicon-user"></i> 
     </h4> 
     <div class="row"> 
      <div class="col-xs-10 col-xs-offset-1"> 
      <h4>{{customer.firstName}} {{customer.lastName}}</h4> 
      <small class="list-group-item-text text-muted"> 
       <span data-ng-bind="customer.created | date:'mediumDate'"></span> 
      </small> 
      </div> 
     </div> 
     </a> 
    </div> 

    <div class="alert alert-warning text-center" data-ng-if="vm.customers.$resolved && !vm.customers.length"> 
     No Customers yet, why don't you <a data-ui-sref="customers.create">create one</a>? 
    </div> 

    <!--<small class="list-group-item-text">--> 
    <!-- {{customer.firstName}}--> 
    <!-- Posted on--> 
    <!-- <span data-ng-bind="customer.created | date:'mediumDate'"></span>--> 
    <!-- by--> 
    <!-- <span data-ng-if="customer.user" data-ng-bind="customer.user.displayName"></span>--> 
    <!-- <span data-ng-if="!customer.user">Deleted User</span>--> 
    <!--</small>--> 


</section> 

// customers.client.controller.js

(function() { 
    'use strict'; 

    // Customers controller 
    angular 
    .module('customers') 
    .controller('CustomersController', CustomersController); 

    CustomersController.$inject = ['$scope', '$state', 'Authentication', 'customerResolve', '$uibModal', '$log']; 

    function CustomersController ($scope, $state, Authentication, customer, $uibModal, $log) { 
    // serialize forms 
    var vm = this; 

    vm.authentication = Authentication; 
    vm.customer = customer; 
    vm.error = null; 
    vm.form = {}; 
    vm.remove = remove; 
    vm.save = save; 
    // vm.customers = customer.query(); 

    // Open a modal window to update a single customer record 
    this.modalUpdate = function (size, selectedCustomer) { 

     var modalInstance = $uibModal.open({ 
     animation: $scope.animationsEnabled, 
     templateUrl: 'modules/customers/client/views/form-customer.client.view.html', 
     controller: function ($scope, $uibModalInstance, customer) { 
      $scope.customer = customer; 
     }, 
     size: size, 
     resolve: { 
      items: function() { 
      return $scope.selectedCustomer; 
      } 
     } 
     }); 

     modalInstance.result.then(function (selectedItem) { 
     $scope.selected = selectedItem; 
     }, function() { 
     $log.info('Modal dismissed at: ' + new Date()); 
     }); 
    }; 

    // Remove existing Customer 
    function remove() { 
     if (confirm('Are you sure you want to delete?')) { 
     vm.customer.$remove($state.go('customers.list')); 
     } 
    } 

    // Save Customer 
    function save(isValid) { 
     if (!isValid) { 
     $scope.$broadcast('show-errors-check-validity', 'vm.form.customerForm'); 
     return false; 
     } 

     // TODO: move create/update logic to service 
     if (vm.customer._id) { 
     vm.customer.$update(successCallback, errorCallback); 
     } else { 
     vm.customer.$save(successCallback, errorCallback); 
     } 

     function successCallback(res) { 
     $state.go('customers.view', { 
      customerId: res._id 
     }); 
     } 

     function errorCallback(res) { 
     vm.error = res.data.message; 
     } 
    } 
    } 
})(); 
+0

你有任何控制台错误? – Nitish

+0

嗨。在edit.html下,如果我删除了data-ng-controller

。它不会有任何控制台错误,弹出窗口不会出现> 如果我离开
,它会给我这个: 'angular.js:11706错误:[$ injector:unpr]未知提供者:customerResolveProvider < - customerResolve < - CustomersController' –

回答

0

移动模态逻辑和依赖于相同控制器在您的路线中被调用(在这种情况下,list-customers.client.controller.js)。

您不能使用data-ng-controller= "CustomersController as customersCtrl",因为其中一个依赖关系需要解析函数,该函数仅在routes.js文件中可用。

相关问题