I have done some research on the error I am getting but nothing has worked. The error:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.15/$injector/modulerr?p0=MemberModule&p1=Re…%20%20at%20http%3A%2F%2Flocalhost%3A3000%2Fjavascripts%2FMemberModule.js%3...<omitted>...5)
Here is my code:
index.jade:
doctype html
html(ng-app="MemberModule")
head
title= title
link(rel='stylesheet', href='/javascripts/vendor/bootstrap-css/css/bootstrap.css')
link(rel='stylesheet', href='/stylesheets/style.css')
script(src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js")
script(src='https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js')
script(type='text/javascript', src='/javascripts/vendor/angular-bootstrap/ui-bootstrap-tpls.js')
script(src='https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js')
script(type='text/javascript', src='/javascripts/MemberModule.js')
#heady
block head
body
block content
As you can see - I think I am loading all the scripts in the correct order.
MemberModule.js:
var MemberModule = angular.module('MemberModule', ['ui.bootstrap', 'ngRoute']);
MemberModule.config(function ($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/member/:id.json', {
templateUrl: '/templates/home.jade',
controller: MemberListCtrl
});
});
MemberModule.controller('MemberListCtrl', ['$scope', '$routeParams',
function ($scope, $routeParams) {
$scope.id = $routeParams.id;
}
]);
I'm guessing its something in MemberModule.js. Thanks in advance.
UPDATE
This is what firefox console says - a little more info, looks like something isn't defined:
[12:34:55.413] Error: [$injector:modulerr] http://errors.angularjs.org/1.2.15/$injector/modulerr?p0=MemberModule&p1=MemberListCtrl%20is%20not%20defined%0A%40http%3A%2F%2Flocalhost%3A3000%2Fjavascripts%2FMemberModule.js%3A9%0Ad%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A33%0Ae%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A32%0Ar%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A7%0Ae%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A32%0AZb%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A35%0AYb%2Fc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A17%0AYb%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A18%0AUc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A17%0A%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A206%0Aa%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A138%0Aie%2Fc%2F%3C%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A30%0Ar%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A7%0Aie%2Fc%40https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.15%2Fangular.min.js%3A30%0A # https://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js:6
UPDATE
Instead of using Google CDN, I downloaded the scripts and put them in the site directory - no more dependency errors - but I do have an error that I'm not sure of (if anyone can help):
[12:42:14.899] ReferenceError: MemberListCtrl is not defined # http://localhost:3000/javascripts/MemberModule.js:9
I updated my MemberModule.js to reflect what it looks like now.
The reason you're getting an undefined error is because it's not defined within the scope of the function trying to use it. Just because you registered an object with that name with Angular doesn't mean that the config function has it. You will need to either inject that controller or specify the controller in the template (my personal preference).
Related
I have a question about Ionic services. As you know, Ionic framework comes with a built in www directory which contains the js directory, which contains the services.js file. My first service works. I attempted to write another service in the same, services.js file and as it turns out, I got an error: Uncaught "SyntaxError: Unexpected token . http://localhost:8100/js/services.js Line: 57" in addition to "(index):28 Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to:
Error: [$injector:modulerr] Failed to instantiate module starter.services due to:
Error: [$injector:nomod] Module 'starter.services' 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." Anyway, here's my code, take a look and let me know what I can do differently. Also, if you need more snippets, let me know!
//services.js
//the first factory, API works
angular.module('starter.services', [])
.factory('API', function($http) {
var apiFooUrl = 'http://localhost:3000/api/do/thing'
return {
all: function(){
return $http.get(apiFooUrl + 's')
},
show: function(thingID){
console.log("stock service get running", thingID);
return $http.get(apiFooUrl + '/' + thingID)
}
};
});
//this is the one that returns the error
.factory('Users', function($http) {
var apiUrl = 'http://localhost:3000/api/users/'
return {
index: function(){
return $http.get(apiUrl)
}
show: function(id){
return $http.get(apiUrl + id)
}
}
})
Edited for more info:
So in response to David L's comment:
I've injected it into my GlobalCtrl like so:
.controller('GlobalCtrl', function(Users, $rootScope, $state, $window,
Things, $scope){
$scope.newUser = {}
$scope.user = {}
//show all Users
Users.index().success(function(results){
$scope.users = results
})
})
It'll also be injected into a DetailCtrl as well.
In app.js, the services are injected like so:
angular.module('starter', ['ionic', 'starter.controllers',
'starter.services'])
There's a lot more that needs to go on eventually so I want to make sure I have it right, now.
Have I included the starter.controllers properly? Do I have to include more than one if I have multiples?
They are indeed included in the index.html file.
you have added service after closing the module,
removing the semicolon will solve this problem
}) //here reomved the semicolon
//this is the one that returns the error
.factory('Users', function($http) {
var myapp = angular.module('myapp', []);
myapp.config(function($interpolateProvider) {
$interpolateProvider
.startSymbol('{[')
.endSymbol(']}');
});
myapp.controller('CanvasControls', function($scope) {
function1($scope);
function2($scope);
});
This code integrate with rails and working in development fine but in production mode it gives below errors.
Failed to instantiate module myapp due to:
Uncaught Error: $injector:modulerr
/$injector/modulerr?p0=myapp
working in development fine but in production mode it gives below
errors
Guess in production you are compressing the code.And I presume you have to add $scope like this
Hope this will help
// Changed here Added String '$scope'
myapp.controller('CanvasControls',['$scope', function($scope) {
function1($scope);
function2($scope);
}]);
EDIT
If you have not modified the .config part please try by making following change.
customInterpolationApp.config(['$interpolateProvider', function($interpolateProvider){
$interpolateProvider.startSymbol('//');
$interpolateProvider.endSymbol('//');
}]);
More about such error
Syntax error added extra ] in controller
myapp.controller('CanvasControls', function($scope) {
function1($scope);
function2($scope);
}]);// remove ']' from here
or use mini-fist way
myapp.controller('CanvasControls', ['$scope',function($scope) {
function1($scope);
function2($scope);
}]);
and you may mismatch module name myapp in controller and in html ng-app="myapp"
Just learning Angular and I'm encountering a few issues with module resolution. In js/directives/directives.js I have the following directive scoped to a directives module:
angular.module("directives").directive("selectList", function() {
return {
restrict: 'E',
link: function() {
// do stuff
}
}
});
On my webpage:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<script>
angular.module("editUserApp", ["directives"])
.controller("editUserController", ['$http', '$scope', function($http, $scope) {
// do stuff here
}]
);
</script>
The error I'm getting is as follows:
Error: [$injector:modulerr] Failed to instantiate module editUserApp due to:
[$injector:modulerr] Failed to instantiate module directives due to:
[$injector:nomod] Module 'directives' 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.
Now, obviously, editUserApp cannot know where directives is, all by itself, so how do I tell it to fetch the directives.js file? Do I have to include it in a script tag (which doesn't seem very scalable)?
I need some way to import directives to my angular app. How can I do this?
You need to include your js/directives/directives.js file into your html and remove the directives dependency on your App module.
your code should be :
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.js"></script>
<script>
angular.module("editUserApp", [])
.controller("editUserController", ['$http','directives', '$scope', function($http, $scope,directives) {
// do stuff here
}]
);
</script>
You need
angular.module("directives" ,[])
in your first block
angular.module("directives")
tries to find an existing module called directives
If you are looking for a way to import these files on a as needed basis, you might want to look at http://requirejs.org/ or http://browserify.org/ or similar tools.
Error in Chrome Developers Tool
Uncaught Error: [$injector:modulerr] Failed to instantiate module polmgr due to:
Error: [$injector:modulerr] Failed to instantiate module polmgr.controllers due to:
Error: [$injector:modulerr] Failed to instantiate module $http due to:
Error: [$injector:nomod] Module '$http' 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 error is coming when i add $http to my module in ionicframework.
I am noob.
I have added the $http in controllers.js file and if i remove everything works fine. but i need to make a http get call.
Find the controllers.js code below :-
angular.module('polmgr.controllers', ['$http'])
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});
Correct Code:-
angular.module('polmgr.controllers', [])
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});
From the looks of things you are trying to inject the $http service incorrectly.
It is part of the core ng module that angular.js/angular.min.js provides.
So you don't need to add it as a module dependency like this:
var ctrlModule = angular.module('polmgr.controllers', [..., '$http', ...])
Instead, just inject it into your controller functions like you would do for $scope:
.controller('PolicyCtrl', function($scope, $http, $stateParams) {
});
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.24/$injector/modulerr?p0=curveApp&p1=Error%…rjs.org%2F1.2.24%2F%24injector%2Fmodulerr%3Fp0%3DngRoute%26p1%3DError%253A...<omitted>...0)
Im getting the above error in my Laravel/Angular application. I went to the URL and I'm still not sure what the error is coming from.
I have a file app.js in project/public/js with this code:
var curveApp = angular.module('curveApp', [
'ngRoute',
'curveControllers'
]);
And then a file config.js in project/public/js with this code:
curveApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/register', {
templateUrl: 'partials/register.html',
controller: 'RegisterCtrl'
});
}
]);
Sorry for the beginner questions -- I'd google to find answers but I'm not quite sure what to be looking for.
I'm trying to create HTML templates in project/public/js/partials and have them switch based on the URI without the page refreshing.
This errors show that, when some of your modules doesn't exist in page and not included, make sure what ngRoute and curveControllers are defined and attached to your DOM.