17

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

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

I'm using NuGet for my package management.

Angularjs: 1.4.8

Bootstrap: 3.3.6

Angular-Ui-Bootstrap: 0.14.3

Here's the relevant code:

Index.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:

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

AbilityListController.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']).

Thanks in advance for any help.

KoalaFanatic
  • 181
  • 1
  • 1
  • 5

5 Answers5

35

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

angular
    .module('tecApp',['ui.bootstrap'])
isherwood
  • 58,414
  • 16
  • 114
  • 157
Ganesh Karamala
  • 513
  • 1
  • 7
  • 13
18

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.

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

It now works like a charm !

Hope it helps ... :)

maxime1992
  • 22,502
  • 10
  • 80
  • 121
  • 3
    https://github.com/angular-ui/bootstrap says: "do not install angular-ui-bootstrap'. A separate repository - bootstrap-bower - hosts the compiled javascript file and bower.json." – Komo Mar 14 '16 at 13:33
  • angular-ui-bootstrap changed its service name from `$modal` to `$uibModal` from version 0.14.0 --> inject the proper service depend on ui-bootstrap's version that you are using – maximus Jun 17 '19 at 06:29
3

Inject ui.bootstrap module into your application module:

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

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

Andrew
  • 1,474
  • 4
  • 19
  • 27
  • 3
    Thanks! Last I heard, $modal is deprecated by ui-bootstrap, and they prefer the use of $uibModal. I'm sure there are some differences, but they seem to function identically. – KoalaFanatic Dec 24 '15 at 17:58
  • This solved my problem. Im using angular 1.4.9 and angular-ui-bootstrap 1.3.2 and on the official page (https://angular-ui.github.io/bootstrap/) they write that you have to use $uibModal but that didn't work for me. – bonbon May 04 '16 at 14:24
0

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.

avitash
  • 19
  • 3
0

I try and solve my issue.

Install latest version of angular-bootstrap

npm install angular-bootstrap or bower install angular-bootstrap