Angular module not available after grunt build even with ng-annotate - angularjs

I am using Yeoman angular genarator. I created Angular module and I try to load it to the app. Grunt is using ng-annotate, vendor scripts (where module is) are loaded before app script, so I don't know what's the problem.
This is commpressed index.html
<!doctype html> <html> <head> <meta charset="utf-8"> <title></title> <meta name="description" content=""> <meta name="viewport" content="width=device-width"> <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> <link rel="stylesheet" href="styles/vendor.20fdc362.css"> <link rel="stylesheet" href="styles/main.16c86e60.css"> </head> <body ng-app="strauiApp"> <!--[if lte IE 8]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please upgrade your browser to improve your experience.</p>
<![endif]--> <div ui-view></div> <script src="scripts/vendor.c9b57eb5.js"></script> <script src="scripts/scripts.7ce0b4a1.js"></script> </body> </html>
This is part of the vendor file where module is registered
function(){"use strict";angular.module("streamlineCore",["configs","ngResource","ui.router","ngMessages","toastr","angular-loading-bar","ipCookie"]).config ...
And this is beggining of the script file
!function(){"use strict";angular.module("strauiApp",["streamlineCore","ui.bootstrap"])}(),
And the error is
Uncaught Error: [$injector:modulerr] Failed to instantiate module strauiApp due to: Error: [$injector:modulerr] Failed to instantiate module streamlineCore due to: Error: [$injector:nomod] Module 'streamlineCore' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
What's wrong in here? What's missing?

Are you sure that streamlineCore module is inserted in scripts/scripts.7ce0b4a1.js before strauiApp module?

It was bootstrap js that caused the problem. This js was automatically added by grunt-wiredep.

Related

angular-ui-bootstrap 2.5.6 not working with AngularJS 1.7.8

I'm new to AngularJS. I'm attempting to convert a project I'm working on that used regular Javascript, jQuery, and Bootstrap into an AngularJS single page project and I'd like to keep using the Bootstrap library for it. I followed the instructions and downloaded the necessary files at http://angular-ui.github.io/bootstrap/ but when I try loading my project at http://localhost:5000 I get none of my page loaded and an error in the console. I downloaded angular-ui-bootstrap in my project with the command "npm install angular-ui-bootstrap" from my Node.JS command prompt
In index.html I have tried changing the order of the script and link tags in my head section to no success. I have also tried removing the 'ui.bootstrap' dependency in main.module.js to see if AngularJS works by only loading my 'recipeList' dependency and it does work.
From main.module.js:
angular.module('mainApp', ['ui.bootstrap', 'recipeList']);
From index.html:
<!DOCTYPE html>
<html ng-app="mainApp">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.7.8/angular.min.js"></script>
<script src="main.module.js"></script>
<script src="recipe-list\recipe-list.module.js"></script>
<script src="recipe-list\recipe-list.component.js"></script>
<title>Sousmate</title>
</head>
<body>
<div id="container">
<header>
<h1>Sousmate</h1>
</header>
<section>
<recipe-list></recipe-list>
</section>
</div>
</body>
</html>
Error: [$injector:modulerr] http://errors.angularjs.org/1.7.8/$injector/modulerr?p0=mainApp&p1=%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.7.8%2F%24injector%2Fmodulerr%3Fp0%3Dui.bootstrap%26p1%3D%255B%2524injector%253Anomod%255D%2520http%253A%252F%252Ferrors.angularjs.org%252F1.7.8%252F%2524injector%252Fnomod%253Fp0%253Dui.bootstrap%250AF%252F%253C%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A7%253A168%250AHe%252F%253C%252F%253C%252F%253C%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A26%253A453%250Ab%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A25%253A478%250AHe%252F%253C%252F%253C%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A26%253A227%250Ag%252F%253C%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A42%253A496%250Ar%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A8%253A76%250Ag%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A42%253A344%250Ag%252F%253C%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A43%253A27%250Ar%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A8%253A76%250Ag%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A42%253A344%250Afb%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A46%253A460%250Ac%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A22%253A57%250AUc%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A22%253A370%250AAe%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A21%253A45%250A%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A348%253A494%250Ab%2540http%253A%252F%252Fajax.googleapis.com%252Fajax%252Flibs%252Fangularjs%252F1.7.8%252Fangular.min.js%253A38%253A444%250A%0AF%2F%3C%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A7%3A168%0Ag%2F%3C%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A43%3A285%0Ar%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A8%3A76%0Ag%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A42%3A344%0Ag%2F%3C%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A43%3A27%0Ar%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A8%3A76%0Ag%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A42%3A344%0Afb%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A46%3A460%0Ac%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A22%3A57%0AUc%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A22%3A370%0AAe%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A21%3A45%0A%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A348%3A494%0Ab%40http%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.7.8%2Fangular.min.js%3A38%3A444%0A
The error is:
Module 'ui.bootstrap' is not available! You either misspelled the
module name or forgot to load it. If registering a module ensure that
you specify the dependencies as the second argument.
From your html I don't see that you've included the angular bootstrap js. You need this file along side your bootstrap css. You can download it here.
e.g.:
<script type="text/javascript" src="ui-bootstrap-tpls-2.5.0.min.js"></script>
Hope this helps!

AngularJS Unknown Provider: $locationProvider

I am using webpack to the run the AngularJS application. My project is first built using webserver, gulp and livereload. Now while trying to build the project using webpack, I'm facing the below error in the console.
Error: Unknown provider: $locationProvider
HTML:
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#25abb7">
<!-- font awesome from BootstrapCDN -->
<link href="assets/fa/font-awesome.min.css" rel="stylesheet">
<!-- compiled JS -->
<script type="text/javascript" src="assets/lib/keycloak/keycloak.js"></script>
<script type="text/javascript" src="../js/bundle.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.js"></script>
<div>
<div ui-view="header"></div>
<div ui-view="main"></div>
<div ui-view="footer"></div>
</div>
Check if your dependency Injection is done right.
Maybe it cannot find the provider because it is minified?
Can you copy your js code ?
Here is an example of how you inject it:
app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider) {
//Do something with the locationProvider
}]);
I think this link might solve your issue How do I access the $locationProvider to configure it?

"ngCordovaOauth is not available" error for ionic app

I have a Ionic app on Android and i want to add an Facebook Login feature using ngCordovaOauth plugin but i get:
0 851065 error Uncaught Error: [$injector:modulerr] Failed to instantiate module
starter due to:
Error: [$injector:modulerr] Failed to instantiate module ngCordovaOauth due to:
Error: [$injector:nomod] Module 'ngCordovaOauth' is not available! You either misspelled
the module name or forgot to load it. If registering a module ensure that you specify
the dependencies as the second argument.
....
I try to load the plugin according to here. I used bower to load the plugin
bower install ng-cordova-oauth -S
Then I added the line to index.html
<script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.min.js"></script>
After that, i added the dependency to module app.js
angular.module('starter', ['ionic','ngMessages','ngCordova','ngCordovaOauth','ksSwiper','starter.services','starter.controllers'])
It gives the error when i added 'ngCordovaOauth'. I also try to download the ng-cordova-oauth.min.js file manually and add it to www/js folder and added
<script src="js/ng-cordova-oauth.min.js"></script>
to the index.html file after i uninstall via bower. This also didn't work. I also try to remove the Android platform and add it again and didn't work.
I think i try everything that i can do but it seems doesn't work. It should find the ngCordovaOauth but it doesn't. Any help is appreciated.
Thanks in advance.
Edit
index.html:
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="default-src *; script-src &apos;self&apos; &apos;unsafe-inline&apos; &apos;unsafe-eval&apos; *; style-src &apos;self&apos; &apos;unsafe-inline&apos; *">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="lib/swiper/dist/css/swiper.min.css" rel="stylesheet"/>
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="lib/swiper/dist/js/swiper.js"></script>
<script src="lib/angular-swiper/dist/angular-swiper.js"></script>
<script src="js/angular-messages.js"></script>
<script src="lib/ng-cordova-oauth/dist/ng-cordova-oauth.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/services.js"></script>
<script src="js/controllers.js"></script>
I had the same error message, although I did install ng-cordova-oauth correctly and I did not misspell its name.
My problem was that I blindly copied
<script src="../ng-cordova-oauth/dist/ng-cordova-oauth.min.js"></script>
from ng-cordova-oauth's README file into my index.html, whereas the path was wrong ! Indeed, the right path was the one you specified in your question : lib/ng-cordova-oauth/dist/ng-cordova-oauth.min.js!
So, to any person having the same issue, I would suggest checking their ng-cordova-oauth.min.js's path in their index.html.

AngularJS - Adding controller files triggering uncaught error

I am creating an angularJS app, and decided to separate the controllers into multiple files. This is what I have:
For declaring the module, I have one file with the below content:
File: controllers.js
angular.module('starter.controllers', []);
and one of the other controllers I am using is called ConnectionsController:
File: ConnectionsController.js
angular.module('starter').controller('ConnectionsController', ['$scope', '$http', function($scope, $http){
}]);
In the app.js, I have the following:
File: app.js
var app = angular.module('starter', ['ionic', 'starter.controllers', 'ConnectionsController','starter.MoreOptionsController','starter.OrdersController', 'starter.ProfileManagementController', 'starter.UserAccessController', 'starter.services']);
When I run the application, it triggers an error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module ConnectionsController due to:
Error: [$injector:nomod] Module 'ConnectionsController' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
What am I doing wrong in declaring the controllers or linking them to app.js file?
Thanks,
Update: Index.html content:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above
<link href="css/ionic.app.css" rel="stylesheet">
-->
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/ConnectionsController.js"></script>
<script src="js/OrdersController.js"></script>
<script src="js/services.js"></script>
</head>
<body ng-app="starter">
<!--
The nav bar that will be updated as we navigate between views.
-->
<ion-nav-bar class="bar-stable">
<ion-nav-back-button>
</ion-nav-back-button>
</ion-nav-bar>
<!--
The views will be rendered in the <ion-nav-view> directive below
Templates are in the /templates folder (but you could also
have templates inline in this html file if you'd like).
-->
<ion-nav-view></ion-nav-view>
</body>
</html>
The error is self-explanatory: you don't have module ConnectionsController. Note, that when you declare main application module like
angular.module('starter', [
'ionic',
'starter.controllers',
'ConnectionsController',
// etc ...
]);
it means that module starter depends on several other modules, in your case ionic, starter.controllers, ConnectionsController. However, ConnectionsController is the controller name it's not a module. So you don't have to list it as module dependency.

Module 'ui.router' is not available

I`m new in AngularJS
I`m getting this error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module ui.router due to:
Error: [$injector:nomod] Module 'ui.router' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
this is index.html file:
<!doctype html>
<html ng-app="app">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Untitled</title>
<link rel="stylesheet" href="css/style.css">
<link rel="author" href="humans.txt">
</head>
<body ng-controller="FirstCtrl">
<input type="text" ng-model="first.greeting"/>
<div ng-class="first.greeting">{{first.greeting}}</div>
<script src="angular.js"></script>
<script src="app/app.js"></script>
<script src="js/main.js"></script>
</body>
</html>
and this is app.js file:
var app = angular.module("app", ["ui.router"]).controller("FirstCtrl", function FirstCtrl(){
var first = this;
first.greeting = "First";
});
Please help me to solve this issue
You're not loading in the ui-router script, I don't know if you have it locally or using a cdn, you just need to add it in your index.html there
for example, by adding-
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js"></script>
in your index.html (this is a cdn link)
Fixed by following steps:
Installed angular-ui-router via npm
npm install angular-ui-router#0.2.18 --save
Then load the script in index.html (angular 1.5.0)
<script src="node_modules/angular/angular.js"></script>
<script src="node_modules/angular-ui-router/release/angular-ui-router.js"></script>
<script src="angular.js"></script>
This is just the core angular library, you need to either download and host the latest angular ui router library or pull it in from a CDN
see here for more details: https://github.com/angular-ui/ui-router
Can be installed via nuget
PM > Install-Package Angular.UI.UI-Router

Resources