Javascript Angularjs - $uibModal 提供程序错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34448354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:21:18  来源:igfitidea点击:

Angularjs - $uibModal provider error

javascriptangularjsangular-ui-bootstrap

提问by KoalaFanatic

I'm trying to inject $uibModal into my project, however when the controller loads, I get the following error:

我试图将 $uibModal 注入我的项目,但是当控制器加载时,我收到以下错误:

Error: [$injector:unpr] Unknown provider: $uibModalProvider <- $uibModal <- abilityListController

I'm using NuGet for my package management.

我正在使用 NuGet 进行包管理。

Angularjs: 1.4.8

Angularjs:1.4.8

Bootstrap: 3.3.6

引导程序:3.3.6

Angular-Ui-Bootstrap: 0.14.3

Angular-Ui-Bootstrap:0.14.3

Here's the relevant code:

这是相关的代码:

Index.html

索引.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8" />
    <link href="Content/bootstrap.css" rel="stylesheet" />
    <script src="scripts/angular.js"></script>
    <script src="scripts/angular-ui/ui-bootstrap.js"></script>
    <script src="app/app.js"></script>
    <script src="app/homeController.js"></script>
    <script src="app/abilityList/abilityListController.js"></script>
</head>
<body>
    <div ng-app="tecApp">
        <div ng-controller="homeController as vm">
            </div>
            <div ng-controller="abilityListController as vm" ng-if="true">
                <div ng-include="'app/abilityList/abilityList.html'"></div>
            </div>
        </div>
    </div>
</body>
</html>

app.js:

应用程序.js:

angular.module("tecApp", []);

AbilityListController.js:

能力列表控制器.js:

angular
    .module('tecApp')
    .controller('abilityListController', AbilityListController);

AbilityListController.$inject = ['$uibModal'];

function AbilityListController($uibModal) {
    var vm = {};
    return vm;
}

I think I'm injecting incorrectly, but it might have to do with how i've included my source files.

我想我的注入不正确,但这可能与我如何包含源文件有关。

I get no console errors aside from the one mentioned above.

除了上面提到的错误之外,我没有收到任何控制台错误。

I prefer this syntax for my angular code, so I'm hoping for a fix to my code rather than using ('controllername', ['$stuff', 'moreStuff']).

对于我的 angular 代码,我更喜欢这种语法,所以我希望修复我的代码,而不是使用 ('controllername', ['$stuff', 'moreStuff'])。

Thanks in advance for any help.

在此先感谢您的帮助。

回答by Ganesh Karamala

You should inject dependent module before you use it. Your code should be like this:

你应该在使用它之前注入依赖模块。你的代码应该是这样的:

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

回答by maxime1992

I lost 3 hours today to figure out that "angular-bootstrap": "0.12.2"should now be "angular-ui-bootstrap": "1.1.2" in your package json.

我今天花了 3 个小时才弄清楚"angular-bootstrap": "0.12.2"现在你的包 json中应该是 "angular-ui-bootstrap": "1.1.2"。

I couldn't understand why version 1.1.2 was not found in angular-bootstrap ...

我不明白为什么在 angular-bootstrap 中找不到 1.1.2 版......

It now works like a charm !

它现在就像一个魅力!

Hope it helps ... :)

希望能帮助到你 ... :)

回答by Andrew

Inject ui.bootstrapmodule into your application module:

ui.bootstrap模块注入您的应用程序模块:

angular.module("tecApp", ["ui.bootstrap"])

Also you can use $modal(and maybe its even better) service from ui.bootstrapmodule instead of $uibModal

您也可以使用$modal(甚至更好)来自ui.bootstrap模块的服务而不是$uibModal

回答by avitash

It worked for me. I had angularJS version 1.2.16. The compatible version of ui-bootstrap is 0.12.0. Need to google the compatible version always before using.

它对我有用。我有 angularJS 版本 1.2.16。ui-bootstrap 的兼容版本是 0.12.0。使用前总是需要谷歌兼容版本。

回答by Divyang Patel

I try and solve my issue.

我尝试解决我的问题。

Install latest version of angular-bootstrap

安装最新版本的 angular-bootstrap

npm install angular-bootstrap or bower install angular-bootstrap