Angular JS - Issue with injector creation - javascript

I'm using angular version 1.3.9 and when I try to create injector by below code I'm getting error - Failed to instantiate module pAll due to:
Error: [$injector:unpr] Unknown provider:
code :-
var app = angular.module('pAll', []);
console.log(angular.injector(['pAll','ng']));
Just like to know
whether to include module name in above injector creation - Correct me if I am worng
If we can't specify module name in injector then how can we get the injector created by the module

It should work. Probably you are getting error because of something else. here is a working example (prints with console.log)
http://plnkr.co/edit/lPZxDVclonGTrpE77KjK?p=preview

Related

angular js syntax errors

I am enough familiar with Javascript as I use it in ajax for PHP but new to AngularJS.
During my first angularJs assignment from "tutorialspoint" I got following error in console:
Error: [$injector:modulerr]
http://errors.angularjs.org/1.3.14/$injector/modulerr?p0=mainApp&p1=%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.3.14%2F%24injector%2Fnomod%3Fp0%3DmainApp%0AM%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A6%3A417%0AOd%2F%3C%2F%3C%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A21%3A412%0Aa%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A21%3A53%0AOd%2F%3C%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A21%3A1%0Ag%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A35%3A46%0As%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A7%3A300%0Ag%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A34%3A399%0Aab%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A38%3A135%0Atc%2Fd%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A381%0Atc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A18%3A179%0AJd%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A17%3A1%0A%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A249%3A428%0Aa%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A163%3A399%0Alf%2Fc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.3.14%2Fangular.min.js%3A32%3A384%0A
Which is not readable at all.
I tried try{} catch(){} but, didn't work.
I couldn't use alert() as angularJS doesn't execute in line.
So I checked line by line and I found out that I had written:
var firstApp = angular.module("mainAp", []);
where I had misspelled data-ng-app which should have been mainApp.
But I couldn't have figured it out if there was 300 lines of code.
so, I wanted to know if there is any simple way to show error very specifically like in php.
"[...] which is not readable at all."
You are using the minified angular.min.js version of Angular. That is a good thing for production (as the file is really smaller), but you can use angular.js during development if you want more readable errors.
To illustrate, this is what you get with the minified version:
Error: $injector:modulerr Module Error Failed to instantiate module
mainApp due to: Error: [$injector:modulerr]
http://errors.angularjs.org/1.4.7/$injector/modulerr?p0=e...)
at Error (native)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:6:416
at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:38:184
at m (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:7:322)
at h (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:37:275)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:37:444
at m (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:7:322)
at h (http://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js:37:275)
...
And with the unminified version:
Error: $injector:nomod
Module Unavailable
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.
Examples source

angular-sweetalert + browserify: how to install/require/inject?

I installed angular-sweetalert ^1.1.2 via npm install --save angular-sweetalert and tried to inject it:
var app = angular.module('myApp', [
require('angular-sweetalert') // doesn't work
]);
I'm getting the following Error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to:
Error: [$injector:modulerr] Failed to instantiate module undefined due to:
Error: [ng:areq] Argument 'module' is not a function, got undefined
It seems like it's depending on more:
include the files in your app
i. SweetAlert.min.js
ii. sweet-alert.js OR sweet-alert.min.js
include the module in angular (i.e. in app.js) - oitozero.ngSweetAlert
Any ideas how to properly install/require the module?
Thanks in advance!
The module injector name is wrong, it should be 'oitozero.ngSweetAlert' rather than 'angular-sweetalert', also don't use require in the module injector. From angular.module says
A module is a collection of services, directives, controllers,
filters, and configuration information. angular.module is used to
configure the $injector.
var app = angular.module('myApp', [
'oitozero.ngSweetAlert'
]);
PS: Make sure all the dependency files (step 2) are included before inject the library module.

Unable to inject Ng-SweetAlert-2 in AngularJS

It is about this project
I have followed the install process given in the description but I'm getting error:
Error: [$injector:unpr] Unknown provider: 19degrees.ngSweetAlert2Provider <- 19degrees.ngSweetAlert2 <- prkctrl`
I have included sweetalert.js (original sweetalert), sweetalert2 (extended version) and ngsweetalert2 (coming from this project).
I still dont see what is the reason? Name can be an issue?
Make sure you have added the module 19degrees.ngSweetAlert2 to your main application like:
angular.module('myApp', ['19degrees.ngSweetAlert2', /* and other modules */]

"Failed to instantiate module ngSanitize" when pre-rendering AngualrJS site with PhantomJS

I'm attempting to pre-render my AngularJS site using PhantomJS. (With phantomjs-runner.js from http://www.yearofmoo.com/2012/11/angularjs-and-seo.html) I'm unable to load the page through PhantomJS as the error below occurs. This error does not occur in IE/Chrome/Firefox.
How do I go about fixing this error?
Error:
Error: [$injector:modulerr] Failed to instantiate module SpaceForAfrica due to:
Error: [$injector:modulerr] Failed to instantiate module dialogs due to:
Error: [$injector:modulerr] Failed to instantiate module ngSanitize due to:
Error: [$injector:nomod] Module 'ngSanitize' 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.
http://errors.angularjs.org/1.2.1/$injector/nomod?p0=ngSanitize
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:1507
at ensure (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:1435)
at module (http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:1717)
at http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.js:3527
Module config
var SpaceForAfrica = angular.module('SpaceForAfrica', ['ngRoute', 'HashBangURLs', 'ui.bootstrap', 'ui.bootstrap.tpls', 'google-maps', 'ui.growl', 'dialogs', 'ngSanitize', 'angularSpinner','angulartics', 'angulartics.google.analytics']).config(spaceForAfricaConfig);
It looks like you might be missing a reference to the ngSanitize code. ngSanitize is part of the AngularJS framework (https://docs.angularjs.org/api/ngSanitize), however, you have to include a separate reference before your PhantomJS reference in order to utilize it.
It appears you are using version 1.2.1 of AngularJS, so you could easily just add one of these tags (or grab the code to include in your own app.)
Non-minified:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.js"></script>
Minified:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-sanitize.min.js"></script>

Failed to instantiate module error in Angular js

I encountered the following error with a root cause of Module 'ngRoute' is not available
Uncaught Error: [$injector:modulerr] Failed to instantiate module
Amail due to:
Error: [$injector:modulerr] Failed to instantiate module ngRoute due
to:
Error: [$injector:nomod] Module 'ngRoute' 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."
Javascript code :
var amailServices = angular.module('Amail',['ngRoute']);
function emailRouteConfig($routeProvider) {
$routeProvider.
when('/', {
controller: ListController,
templateUrl : 'list.html'}).
when('/view/:id',{
controller : DetailsController,
templateUrl:'detail.html'}).
otherwise({
redirectTo:'/'
});
}
amailServices.config(emailRouteConfig);
How to fix this
You need to include angular-route.js in your HTML:
<script src="angular-route.js">
http://docs.angularjs.org/api/ngRoute
Or the minified version of the file...
<script src="angular-route.min.js"></script>
More information about this here:
"This error occurs when a module fails to load due to some exception. The error message above should provide additional context."
"In AngularJS 1.2.0 and later, ngRoute has been moved to its own module. If you are getting this error after upgrading to 1.2.x, be sure that you've installed ngRoute."
Listed under section Error: $injector:modulerr Module Error in the Angularjs docs.
For me the solution was fixing a syntax error:
removing a unwanted semi colon in the angular.module function
I got this error due to not pointing the script to the correct path. So make absolutely sure that you are pointing to the correct path in you html file.
For me the error occurred due to my browser using a cached version of the js file containing the module. Clearing the cache and reloading the page solved the problem.
Such error happens when,
1. You misspell module name which you injected.
2. If you missed to include js file of that module.
Sometimes people write js file name instead of the module name which we are injecting.
In these cases what happens is angular tries to look for the module provided in the square bracket []. If it doesn't find the module, it throws error.

Categories

Resources