AngularUI为模态控制器分隔文件

时间:2021-11-10 10:29:28

My Angular application has a number of modals, and I have AngularUI to provide the modal directive.

我的Angular应用程序有许多模态,我有AngularUI来提供模态指令。

http://angular-ui.github.io/bootstrap/

http://angular-ui.github.io/bootstrap/

So far I have several main controllers, and these are all in the app.js file as routes.

到目前为止,我有几个主控制器,这些都在app.js文件中作为路由。

$routeProvider.when '/dashboard',         templateUrl: '/templates/dashboard/dashboard.html', controller: 'DashboardController'
$routeProvider.when '/dataset/:panel_id', templateUrl: '/templates/dataset/dataset.html',   controller: 'DatasetController'
$routeProvider.when '/batches/:panel_id', templateUrl: '/templates/design/design.html',     controller: 'PanelController'  

This works fine.

这很好用。

Then I created a function which calls a modal, and the modal has an instance controller of ConfigureModalCtrl. I initially had this at the bottom of the calling controller file, and it worked OK.

然后我创建了一个调用模态的函数,模态有一个ConfigureModalCtrl的实例控制器。我最初在调用控制器文件的底部有这个,它工作正常。

$scope.invokeConfigureModal = (assay_id) ->
   $scope.assay_id = assay_id
   $scope.primer3 = $scope.getPrimer(assay_id)
   modalInstance = $modal.open(
     templateUrl: '/templates/configure_modal/configure_modal.html'
     controller: ConfigureModalCtrl
     windowClass: 'configure-dialog'
     resolve:
           primer3: ->
             $scope.primer3
   )
   modalInstance.result.then ((primer3) ->
      $scope.primer3 = primer3
      return
     ), ->
      return   

Now I have moved the modal instance controller into it's own file, but the calling function cannot find it.

现在我已将模态实例控制器移动到它自己的文件中,但调用函数找不到它。

angular.module('assaypipelineApp').controller "ConfigureModalCtrl", ($scope,  $modalInstance, primer3) ->
  $scope.primer3 = primer3['data']
  $scope.ok = ->  
    $modalInstance.close $scope.primer3
    return
  $scope.cancel = ->
    $modalInstance.dismiss "cancel"
  serverErrorHandler = ->
    alert("There was a server error, please reload the page and try again.")

Error message

错误信息

Error: Unknown provider: ConfigureModalCtrlProvider <- ConfigureModalCtrl

Similar question but does not resolve my problem. How to create separate AngularJS controller files?

类似的问题,但不解决我的问题。如何创建单独的AngularJS控制器文件?

So how can I resolve this problem, and why does this not occur for the other (non-modal instance) controllers? Is it because they are named in the routes?

那么我该如何解决这个问题,为什么其他(非模态实例)控制器不会出现这种情况呢?是因为它们在路线中被命名了吗?

Any recommendations on coding style are welcome also ... thanks for reading this.

有关编码风格的任何建议也欢迎...感谢阅读本文。

1 个解决方案

#1


11  

Try putting the controller as a string -- I had a similar issue.

尝试将控制器作为字符串 - 我遇到了类似的问题。

controller: 'ConfigureModalCtrl'

#1


11  

Try putting the controller as a string -- I had a similar issue.

尝试将控制器作为字符串 - 我遇到了类似的问题。

controller: 'ConfigureModalCtrl'