help me to solve error while using service from one module to another module controller ITS IMPORTANT SO THAT I START MY PROJECT

42 views
Skip to first unread message

Sandeep Jsk

unread,
Nov 30, 2014, 1:27:47 PM11/30/14
to ang...@googlegroups.com
angular.module('myApp', []).controller('MainController', ['helloDude','$scope', function($rootScope,helloDude) {
        $rootScope.$on("$routeChangeStart", ['$scope',function() {
            var sss=helloDude.user();
            console.log("In main controller and event is fired"+sss);
            alert("Event is fired");
        }]);
    }]);


angular.module('hellService',[]).service('helloDude', function() {
//    var user= function(){
        return "hello";
        alert("in service");
//    };
});

ERROR:Error: [$injector:unpr] http://errors.angularjs.org/1.2.26/$injector/unpr?p0=helloDudeProvider%20%3C-%20helloDude
http://ajax.googleapis.com/ajax/libs/angularjs/1.2.26/angular.min.js
Line 6



OR

Eric Eslinger

unread,
Nov 30, 2014, 1:50:55 PM11/30/14
to ang...@googlegroups.com
 ['helloDude','$scope', function($rootScope,helloDude) {

should be 

['$rootScope', 'helloDude', function($rootScope, helloDude) {

if you want to use that notation. Personally, I just use ng-annotate instead.

e

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Eric Eslinger

unread,
Nov 30, 2014, 1:52:33 PM11/30/14
to ang...@googlegroups.com
Oh, also, you need to declare angular.module('myApp', ['hellService']) if you want access to helloDude in the myApp module, since you declared it in the other module. I'd recommend a good read through of the angularJs documentation.

e

To unsubscribe from this group and stop receiving emails from it, send an email to angular+unsubscribe@googlegroups.com.

Sandeep Jsk

unread,
Dec 1, 2014, 12:26:37 AM12/1/14
to ang...@googlegroups.com
Thank you Eric Eslinger .

regards
sandeep kumar

Reply all
Reply to author
Forward
0 new messages