module was created but never loaded angularjs - angularjs

I have read just about all the related responses to this question including this Why is my AngularJS module never loaded? and a few others and some how I am just not getting it right
this is what my app.js looks like
'use strict';
var appAcademia = angular.module("appAcademia", ['seblucas.slPageSizeChanger', 'LocalStorageModule', 'ngRoute', 'ngAnimate', 'ui.bootstrap', 'ui.router', 'ngResource']).config(function ($routeProvider, $stateProvider, $urlRouterProvider, $httpProvider, $resourceProvider) {
$httpProvider.interceptors.push('authInterceptorService');
$resourceProvider.defaults.stripTrailingSlashes = false;
$routeProvider.when('/home',
{
templateUrl: '/Home/Home',
controller: 'HomeController'
});
$routeProvider.when('/management',
{
templateUrl: '/management',
controller: 'ManagementController',
controllerAs: 'vm',
secure: true
});
$routeProvider.when('/createschoolmanagement',
{
templateUrl: '/management/createSchoolManagement',
controller: 'ManagementController',
controllerAs: 'vm',
secure: true
});
$routeProvider.when('/getschoolmanagement',
{
templateUrl: '/management/GetSchoolManagement',
controller: 'ManagementController',
controllerAs: 'vm',
secure: true
});
$routeProvider.when('/login',
{
templateUrl: '/home/login',
controller: 'LoginController'
});
$routeProvider.when('/signup',
{
templateUrl: '/home/signup',
controller: 'SignupController'
});
$routeProvider.when('/welcome',
{
templateUrl: '/home/welcome',
controller: 'WelcomeController'
});
$routeProvider.when('/users',
{
templateUrl: '/home/users',
controller: 'UsersController',
controllerAs: 'vm',
secure: true
});
//$routeProvider.when('/roles/:userId',
// {
// templateUrl: '/home/roles',
// controller: 'UserEditController',
// controllerAs: 'vm',
// secure: true
// });
$routeProvider.when('/createuser/:userId', {
controller: 'UserEditController',
templateUrl: '/home/EditUser',
controllerAs: 'vm',
secure: true //This route requires an authenticated user
});
$routeProvider.otherwise(
{
redirectTo: '/home'
});
});
var authServiceBase = 'http://localhost:26264/';
var resourceServiceBase = 'http://localhost:47039/';
appAcademia.constant('ngAuthSettings', {
apiAuthServiceBaseUri: authServiceBase,
apiResourceServiceBaseUri: resourceServiceBase,
clientId: '414e1927a3884f68abc79f7283837fd1'
});
appAcademia.run(['authService', function (authService) {
authService.fillAuthData();
}]);
All the modules below are created but never loaded
Then I get the following error message in the console
"Uncaught Error: [$injector:nomod] Module 'appAcademia' 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.3.0-build.3042+sha.76e57a7/$injector/nomod?p0=appAcademia"
when I run CCleaner and run the application again I get this error below
Uncaught Error: [$injector:nomod] Module 'appAcademia' 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.4.8/$injector/nomod?p0=appAcademia
Now watch the Url in both cases. The first one refers to angular 1.3.0 and the second one refers the version 1.4.8 which is the one i actually installed
i have tried out the best practices all to no avail. I have been at this for weeks.
Modules (63)
The best practice for module names is to use dot.case or lowerCamelCase. Check the name of "LocalStorageModule".
Module "ngRoute" was created but never loaded.
Module "ngAnimate" was created but never loaded.
Module "ngResource" was created but never loaded.
Module "LocalStorageModule" was created but never loaded.
Module "ui.router.util" was created but never loaded.
Module "ui.router.router" was created but never loaded.
Module "ui.router.state" was created but never loaded.
Module "ui.router" was created but never loaded.
Module "ui.router.compat" was created but never loaded.
Module "appAcademia" was created but never loaded.

OK, now that I looked at your code, I understand your issue. It's with this line
var appAcademia = angular.module("appAcademia",
['seblucas.slPageSizeChanger', 'LocalStorageModule', 'ngRoute', 'ngAnimate',
'ui.bootstrap', 'ui.router', 'ngResource']).config(function ($routeProvider, $stateProvider, $urlRouterProvider, $httpProvider, $resourceProvider)
You're setting the variable to the module name's config function. Instead do this
var appAcademia = angular.module("appAcademia",
['seblucas.slPageSizeChanger', 'LocalStorageModule', 'ngRoute', 'ngAnimate',
'ui.bootstrap', 'ui.router', 'ngResource']);
appAcademia.config(function ($routeProvider, $stateProvider, $urlRouterProvider, $httpProvider, $resourceProvider)

Related

Angular error, in npm build [$injector:nomod] Module 'testApp' is not available

Studying and practicing about npm build, im trying to compile my script using npm run build and i got an error
[$injector:nomod] Module 'testApp' 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.
any advice. thanks
app.js
import angular from 'angular';
import 'angular-ui-router';
import './services/router.js';
angular.module('testApp', [
'ui-router'
]);
-----------------------------
my roter.js
'use strict';
angular
.module('testApp')
.config([
'$urlRouterProvider',
'$stateProvider',
'$locationProvider',
function($urlRouterProvider, $stateProvider, $locationProvider) {
$locationProvider.html5Mode(false).hashPrefix('');
$urlRouterProvider.otherwise('/');
$stateProvider
.state('home', {
url: '/',
templateUrl: 'components/views/homepage.html',
controller: 'productController'
})
.state('about', {
url: '/about',
templateUrl: 'components/views/about.html'
})
.state('product', {
url: '/product/:id/:name',
templateUrl: 'components/views/product.html',
controller: 'productViewController'
})
}]);
Change
From
angular.module('testApp', [
'ui-router'
]);
To
angular.module('testApp', [
'ui.router'
]);

An error when I add $state service to my references in angularjs module

I have some problems to use $state service on my tutorial project.
Here is my module and config definition:
(function () {
"use strict";
angular.module("gameManagement", ["ui.router", "ngAnimate", "ngResource"])
.config(["$stateProvider", "$urlRouterProvider","$state", function ($stateProvider, $urlRouterPorvider,$state) {
$urlRouterPorvider.otherwise("/game/MultiStepForm/step1");
$urlRouterProvider.otherwise("/game/Home");
$stateProvider
.state("Home", {
url: "/game/Home",
templateUrl: "/app/game/GameView.html",
controller: "GameController",
controllerAs: "vm"
});
$stateProvider
.state("Log", {
url: "/Game/Log",
templateUrl: "/app/Log/GameLogView.html",
controller: "GameLogController",
controllerAs: "vm"
onEnter: function () {
$state.go("MultiStepForm");
}
});
$stateProvider
.state("MultiStepForm.view", {
url: "/Game/MultiStepFormView",
templateUrl: "/app/MultiStepForm/MultiStepFormView.html",
controller: "MultiStepFormViewController",
controllerAs: "MultiStepViewLogic"
})
$stateProvider
.state("MultiStepForm.Edit", {
url: "/Game/MultiStepFormEdit",
templateUrl: "/app/MultiStepFormEdit/MultiStepForm.html",
controller: "MultiStepFormEditController",
controllerAs: "MultiStepEditLogic"
})
}]);
})();
I want to use this row:
$state.go();
for this purpose I add $state service to references but, when I add to
references the $state service I start to get this error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module sensorManagement due to:
Error: [$injector:unpr] Unknown provider: $state
http://errors.angularjs.org/1.4.2/$injector/unpr?p0=%24state
...
Any idea why I get the error above? What am I missing?
You could only access provider inside config phase of angular, $state dependency won't be available inside that phase because $state is provider, and you are already accessing it inside config function by appending Provider prefix like $stateProvider.
If you aim is to redirect the route then you could use $state dependency in run block. Do use $state.go from there
app.run(function($state){
$state.go('somestate')
})
I believe you are missing a resolution in your state. You could try something like this:
$stateProvider
.state("Log", {
url: "/Game/Log",
templateUrl: "/app/Log/GameLogView.html",
controller: "GameLogController",
controllerAs: "vm",
resolve: {$state: '$state'},
onEnter: function ($state) {
$state.go("MultiStepForm");
}
});
See the documentation for more information on how the onEnter and onExit callbacks work. Basically the above question doesn't inject the $state service correctly and thus, is unable to transition state(s) due to the callback lacking access to $state.
You will also want to remove the injection into the config:
.config(["$stateProvider", "$urlRouterProvider", function ($stateProvider, $urlRouterProvider) {

how to install underscore.js in my angular application?

I used yo-angular to generate my angularjs template with bootstrap/grunt/bower. I also want to use underscore in the app:
npm install underscore --save-dev
In the MainCtrl I am calling underscore.js just to see whether it works:
angular.module('yomanApp')
.controller('MainCtrl', function ($scope) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'AngularJS'
];
_.each([1,2,3],console.log);
});
When I run the application with Chrome I get this errmsg in the console:
ReferenceError: _ is not defined
at new <anonymous> (http://localhost:9000/scripts/controllers/main.js:18:5)
at invoke (http://localhost:9000/bower_components/angular/angular.js:4203:17)
at Object.instantiate (http://localhost:9000/bower_components/angular/angular.js:4211:27)
at http://localhost:9000/bower_components/angular/angular.js:8501:28
at link (http://localhost:9000/bower_components/angular-route/angular-route.js:975:26)
at invokeLinkFn (http://localhost:9000/bower_components/angular/angular.js:8258:9)
at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7768:11)
at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7117:13)
at publicLinkFn (http://localhost:9000/bower_components/angular/angular.js:6996:30)
at $get.boundTranscludeFn (http://localhost:9000/bower_components/angular/angular.js:7135:16) <div ng-view="" class="ng-scope">
After this error I added the module to the app config:
'use strict';
/**
* #ngdoc overview
* #name yomanApp
* #description
* # yomanApp
*
* Main module of the application.
*/
angular
.module('yomanApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'underscore'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/accordeon', {
templateUrl: 'views/accordeon.html',
controller: 'IssuesCtrl'
})
.otherwise({
redirectTo: '/'
});
});
Now I am getting this error:
Uncaught Error: [$injector:modulerr] Failed to instantiate module yomanApp due to:
Error: [$injector:modulerr] Failed to instantiate module underscore due to:
Error: [$injector:nomod] Module 'underscore' 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.
Last thing I tried was adding it to the index.html:
<script src="node_modules/underscore/underscore.js"></script>
This results in the same error as above. Also get a 404 for the underscore.js?? Is this a grunt configuration issue or anything else?
I tend to just use a constant for this type of thing. It's a simple approach and allows you to explicitly state your dependencies in your application.
Install with bower:
bower install underscore --save
Load the library before angular:
<script src="bower_components/underscore/underscore.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="app/scripts/app.js"></script>
Define it as a constant (in app/scripts/app.js for example):
application.constant('_',
window._
);
Then in your controllers/services:
application.controller('Ctrl', function($scope, _) {
//Use underscore here like any other angular dependency
var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];
$scope.names = _.pluck(stooges, 'name');
});
Create a module with the name of underscore a module and then you can pass it in your application and it will be accessible. Currently the underscore module is undefined and hence you are getting this errror.
Your app becomes like this:
var underscore = angular.module('underscore', []);
underscore.factory('_', function() {
return window._; //Underscore should be loaded on the page
});
angular
.module('yomanApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ngRoute',
'ngSanitize',
'ngTouch',
'underscore'
])
.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.when('/about', {
templateUrl: 'views/about.html',
controller: 'AboutCtrl'
})
.when('/accordeon', {
templateUrl: 'views/accordeon.html',
controller: 'IssuesCtrl'
})
.otherwise({
redirectTo: '/'
});
})
.controller('MainCtrl', function ($scope, _) {
$scope.awesomeThings = [
'HTML5 Boilerplate',
'AngularJS',
'AngularJS'
];
_.each([1,2,3],console.log);
});
Here's how you do it:link
You basically need to add angular underscore module which acts as a bridge between the two.

AngularJS - Dependency injection on controllers module

Having real issues wrapping my head around an issue I'm having with Angular. I'm trying to set up a multi-page app with routing. My app.js looks a little something like this:
var app = angular.module('app', ['angularLocalStorage', 'ngRoute', 'ngResource', 'authControllers', 'authServices', 'eventControllers', 'eventServices']);
app.config(['$routeProvider', '$httpProvider',
function($routeProvider, $httpProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/events.html',
controller: 'EventListController'
}).
otherwise({
redirectTo: '/'
});
...
I'm attempting to make my module - app depend on eventControllers, but I'm getting the following error:
Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=app&p1=%5B%24injector%3Amodulerr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.3.15%2F%24injector%2Fmodulerr%3Fp0%3DeventControllers%26p1
This leads me to believe that it can't load eventController module for whatever reason.
My controllers.js looks a little something like this:
(function () {
var authControllers = angular.module('authControllers', []);
var eventControllers = angular.module('eventControllers', []);
eventControllers.config(function($stateProvider) {
$stateProvider.state('events', { // state for showing all events
url: '/events',
templateUrl: 'partials/events/list.html',
controller: 'EventListController'
}).state('viewMovie', { //state for showing single event
url: '/events/:id/view',
templateUrl: 'partials/events/single.html',
controller: 'EventViewController'
}).state('newMovie', { //state for adding a new event
url: '/events/new',
templateUrl: 'partials/events/create.html',
controller: 'EventCreateController'
}).state('editMovie', { //state for updating a event
url: '/events/:id/edit',
templateUrl: 'partials/events/edit.html',
controller: 'EventEditController'
});
}).run(function($state) {
$state.go('events'); //make a transition to events state when app starts
});
I'm sure the answer is very simple, and I'm missing something basic, but I'd really appreciate any pointers.
The eventControllers module is only declared inside the controllers.js, could this be an issue?

angularjs translate can't use with angular ui router?

I am new with Angularjs
and I want to use angular-translate
here is the site
http://pascalprecht.github.io/angular-translate/
I refer it document , and I got the error
Uncaught TypeError: Cannot call method 'useStaticFilesLoader' of undefined from remoteApp
here is my code
app.js
angular.module('remoteApp', ['ui.bootstrap', 'ui.router', 'ngResource', 'truncate',
'pascalprecht.translate'])
.config(['$translateProvider', function ($routeProvider, $stateProvider, $urlRouterProvider,
$translateProvider) {
$translateProvider.useStaticFilesLoader({
prefix: 'languange/locale-',
suffix: '.json'
});
$translateProvider.preferredLanguage('en');
$translateProvider.useLocalStorage();
$stateProvider
.state('index', {
url: "",
views: {
"viewA": {
templateUrl: "views/main.html",
controller: 'MainCtrl'
},
"viewB": {
templateUrl: "views/appList.html",
controller: 'MainCtrl'
},
"viewC": {
templateUrl: "views/appTree.html",
controller: 'ApptreeCtrl'
}
},
})
.state('applicatoion', {
url: "/applicatoion",
views: {
"viewA": {
templateUrl: "views/main.html",
controller: 'MainCtrl'
},
"viewB": {
templateUrl: "views/appList.html",
controller: 'MainCtrl'
},
"viewC": {
templateUrl: "views/appTree.html",
controller: 'ApptreeCtrl'
}
}
})}]);
I have no idea about it ,
please help
Right now this is how you are calling .config
config(['$translateProvider', function ($routeProvider, $stateProvider, $urlRouterProvider,
$translateProvider) {
// ...
}]);
.config has its parameters ( dependencies ) injected by AngularJS, there are two ways to call config;
1 - Pass in a function and AngularJS will read the parameter names and find the matching dependencies.
2 - Pass in an array, of which the last item is a function, and the other items are names of dependencies, if you use this, AngularJS will not read the function's parameter names. The reason this exists is so you can minify your code; because minifying would change the parameter names, and AngularJS uses those names to find dependencies.
What you have now is you specify only one dependency, '$translateProvider', which means the first parameter being passed to the function is the translateProvider, and the other parameters end up being undefined, because you didn't ask for more dependencies.
What you can do is either let AngularJS read your dependency names like this
config(function ($routeProvider, $stateProvider, $urlRouterProvider, $translateProvider) {
// ...
});
Or you can specify all of the dependencies, matching the function parameter list like this, allowing you ( only if you do this consistently ) to minify your code without breaking it.
config(['$routeProvider', '$stateProvider', '$urlRouterProvider', '$translateProvider',
function ($routeProvider, $stateProvider, $urlRouterProvider, $translateProvider) {
// ...
}]);

Resources