如何为多个控制器使用bootstrap模式?

时间:2016-09-12 20:35:49

标签: javascript angularjs twitter-bootstrap

我想在不同的父控制器中使用相同的模态窗口,模态控制器的唯一区别是我正在调用的单独工厂,例如df['Month'] = pd.to_datetime(df.Month.astype(str) + '-01-' + df.Year.astype(str)) df = df.set_index('Month') .groupby(['Part_ID','Year']) .resample('MS') .asfreq() .fillna(0) .drop(['Part_ID','Year'], axis=1) .reset_index() df['Month'] = df['Month'].dt.month print (df) Part_ID Year Month Qty Sales 0 ZZSSL 2007 5 11.0 724.85 1 ZZSSL 2007 6 7.0 537.94 2 ZZSSL 2007 7 17.0 1165.02 3 ZZSSL 2007 8 3.0 159.56 4 ZZSSL 2007 9 67.0 4331.28 5 ZZSSL 2007 10 72.0 4582.98 6 ZZSSL 2007 11 0.0 0.00 7 ZZSSL 2007 12 42.0 2651.42 8 ZZSSL 2008 1 22.0 1422.32 9 ZZSSL 2008 2 16.0 1178.98 10 ZZSSL 2008 3 20.0 1276.60 11 ZZSSL 2008 4 28.0 2120.84 12 ZZSSL 2008 5 2.0 83.03 13 ZZSSL 2008 6 16.0 1250.24 14 ZZSSL 2008 7 0.0 0.00 15 ZZSSL 2008 8 0.0 0.00 16 ZZSSL 2008 9 17.0 1323.34 17 ZZSSL 2008 10 2.0 197.98 18 ZZSSL 2009 1 21.0 1719.30 19 ZZSSL 2009 2 1.0 78.15 20 ZZSSL 2009 3 3.0 281.34 21 ZZSSL 2009 4 25.0 2214.25 22 ZZSSL 2009 5 10.0 833.60 23 ZZSSL 2009 6 1.0 83.36 24 ZZSSL 2009 7 1.0 83.36 所以类似我想在模态填充Ctrl-1-Factory.getServerFiles时调用Ctrl-2-Factory {1}}。

ModalCtrl.js

Ctrl2

CTRL-1.js

angular.module('App').controller('ServerFilesCtrl', function($scope, $rootScope, FileSaver, $uibModalInstance, Ctrl-1-Factory, $uibModal) {
    'use strict';
    $scope.cancel = function() {
        $uibModalInstance.close();
    }
    Ctrl-1-Factory.getServerFiles().then(function(response) {
        $scope.data = response.data;
        console.log($scope.data);
    });
});

Ctrl-2.js

 $scope.modalInstance = $uibModal.open({
         templateUrl: '/web/global/modal.html',
            controller:'ModalController'
         });

1 个答案:

答案 0 :(得分:0)

您可以将其包装在服务方法中。

angular.module('App').factory('FilesModal', function() {
  return {
    openModal: openModal
  };

  function openModal() {
    return $uibModal.open({
      templateUrl: '/web/global/modal.html',
      controller: 'ModalController'
    });
  }
});

angular.module('App').controller('Ctrl1', function(FilesModal) {
  $scope.someEventFunction = someEventFunction;

  function someEventFunction() {
    $scope.modalInstance = FilesModal.openModal();
  }
});

根据需要传递参数以使其更健壮