admin管理员组

文章数量:1429407

In my app.js I have

var app = angular.module("atlas", ["ngRoute", "ngDialog"]);

for my controller I have

app.controller("nodeController", function ($scope, $http, ngDialog)

the ngDialog makes the error:

>Error: [$injector:unpr] Unknown provider: ngDialogProvider <- ngDialog <-nodeController

also I used refrenced css and js files

<link rel="stylesheet" href="~/Content/ngDialog-custom-width.css" />
<link rel="stylesheet" href="~/Content/ngDialog-theme-default.min.css" />
<link rel="stylesheet" href="~/Content/ngDialog-theme-plain.min.css" />
<link rel="stylesheet" href="~/Content/ngDialog.css" />

<script src="~/Scripts/jquery-2.1.3.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/ngDialog.js"></script>

I tried all answers on stackoverflow and none of them work for me

In my app.js I have

var app = angular.module("atlas", ["ngRoute", "ngDialog"]);

for my controller I have

app.controller("nodeController", function ($scope, $http, ngDialog)

the ngDialog makes the error:

>Error: [$injector:unpr] Unknown provider: ngDialogProvider <- ngDialog <-nodeController

also I used refrenced css and js files

<link rel="stylesheet" href="~/Content/ngDialog-custom-width.css" />
<link rel="stylesheet" href="~/Content/ngDialog-theme-default.min.css" />
<link rel="stylesheet" href="~/Content/ngDialog-theme-plain.min.css" />
<link rel="stylesheet" href="~/Content/ngDialog.css" />

<script src="~/Scripts/jquery-2.1.3.min.js"></script>
<script src="~/Scripts/angular.js"></script>
<script src="~/Scripts/angular-route.js"></script>
<script src="~/Scripts/ngDialog.js"></script>

I tried all answers on stackoverflow and none of them work for me

Share Improve this question edited Oct 27, 2015 at 5:05 andand 17.5k11 gold badges60 silver badges83 bronze badges asked Apr 11, 2015 at 9:17 DisposerDisposer 6,3815 gold badges34 silver badges39 bronze badges 2
  • @dfsq, this is all the code. the problem is when I'm not using ngDialog as parameter for controller, everything works fine (when I add the ngDialog as parameter, I get the error), but I want ngDialog for modal windows. – Disposer Commented Apr 11, 2015 at 9:29
  • 1 It means that there is no module ngDialog. Check that script is indeed loaded, correct path, no errors/ – dfsq Commented Apr 11, 2015 at 9:29
Add a ment  | 

2 Answers 2

Reset to default 2

the problem was the config of ngDialogProvider

after var app = angular.module("atlas", ["ngRoute", "ngDialog"]);

we have to use:

app.config(["ngDialogProvider", function (ngDialogProvider) {
    ngDialogProvider.setDefaults({
        className: "ngdialog-theme-default",
        plain: false,
        showClose: true,
        closeByDocument: true,
        closeByEscape: true,
        appendTo: false,
        preCloseCallback: function () {
            console.log("default pre-close callback");
        }
    });
}]); 

I experienced the same error message when I first tried to add ngDialog to my app, and I tried the ngDialogProvider fix outlined by Disposer above. It didn't work for me. Then I realised that my app was partitioned into two modules; a top level module defining the controller, and core module defining a service with some lower level code. My code is structured that way because I started with the angular-phonecat tutorial as boilerplate. I was injecting ngDialog into the controller, and attempting to use it in the service. Once I fixed the injection to be into the correct module the issue was resolved.

本文标签: javascriptquotUnknown provider ngDialogProviderquotStack Overflow