15

I am trying to replicate the following Angular UI example of a simple dialog with a close-button. https://github.com/angular-ui/bootstrap/blob/master/src/dialog/README.md. However, I cannot get the dialog parameter to be injected properly into my dialog controller.

The controllers looks like below (using CoffeScript)

angular.module('myApp', ['ui.bootstrap'])

angular.module('myApp').controller 'MyController', ($dialog, $scope) ->
  $dialog.dialog().open('dialogTemplate', 'DialogController')

angular.module('myApp').controller 'DialogController', ['$scope', 'dialog', ($scope, dialog) ->
    $scope.close = -> dialog.close()
]

See the Plunker for a live version: http://plnkr.co/edit/ejKh7w8Sk9H7Nz3rXhdc?p=preview

Angular gives me the following error:

Unknown provider: dialogProvider <- dialog

Any ideas on how the dialog-parameter could be injected into DialogController, as is seen in the docs example referred to above? I suspect this could have something to do with CoffeeScript since I am fairly new to this language, but it seems quite right when I look at the compiled output.

nip3o
  • 3,346
  • 4
  • 24
  • 29

3 Answers3

18

I had a similar problem and was struggling to find a solution.

I was expecting two additional arguments to my controller; ..., selectedView, dialog). It seemed to provide my dialog with the right arguments, but I still got an error in the console.

The problem was that I was referencing the controller twice;

  1. When opening my dialog: dialog.open('template', 'myController')
  2. In my template file: section(ng-controller='myController')

Removing (2) resolved the problem, since that wasn't invoked by the dialog code, which provided my selectedView argument and the default dialog argument.

Hope that helps someone.

Kristofer Sommestad
  • 3,061
  • 27
  • 39
0

The dialog provider is named $dialog (s. dialog.js). So you have to name the injected value $dialog like you did correctly in MyController.

angular.module('myApp').controller 'DialogController', ['$scope', '$dialog', ($scope, $dialog) ->
  $scope.close = -> dialog.close()
]

Plunker

Note: As you define your dependencies as strings the controller arguments can be named as you like:

... ['$scope', '$dialog', (myscope, mydialog) -> ...
Reto Aebersold
  • 16,306
  • 5
  • 55
  • 74
  • 1
    this is not correct. $dialog is the angular ui injector, dialog is the singleton object of the current dialog. ['$scope', '$dialog', (myscope, mydialog) doesn't make sense either because this construction is used only to avoid minification problems. see Kristofer's answer for possible solution. – mackmack Jun 15 '13 at 05:42
0

Kristofer Sommestad is right here. but i got the same problem.problem was some older version of ui-bootstrap-tpls(like version 0.11.0) does not support $dialog.so used new version of ui-bootstrap-tpls.

Mukund Kumar
  • 21,413
  • 18
  • 59
  • 79