0

I am very new to Angularjs and this is my first try to build an app with it. I've following file loaded in my index.html file.

<!--Angularjs-->
<script src="assets/js/vendor/angular.min.js" type="text/javascript"></script>
<script src="assets/js/vendor/angular-route.min.js" type="text/javascript"></script>

<!--SleekDocketAppJS-->
<script src="app/app.module.js" type="text/javascript"></script>
<script src="app/app.route.js" type="text/javascript"></script>

<!--Controllers-->
<script src="app/components/dashboard/controller/dashboardController.js" type="text/javascript"></script>
<script src="app/components/product/controller/productController.js" type="text/javascript"></script>

His is my app.module.js file and I am trying to add a factory here name AuthFactory

'use strick';

var docket = angular.module("docket",['ngRoute']);

//Factory
docket.factory('AuthFactory',function(){

    console.log('auth factory');
    var authdata = {};
    authdata.name = "user 1";
    return (authdata);
});

//Running
docket.run(function(){
    console.log("runing...");
});

This is my app.route.js file where I am calling my controllers based on route.

'use strict';

var docket = angular.module('docket');

docket.config(['$routeProvider',function($routeProvider){
    $routeProvider
    .when("/",
    {
            controller:"DashboardController",
            templateUrl: "app/components/dashboard/view/dashboard.html"
        })
        .when("/product",{
            controller:"productController",
            templateUrl: "app/components/product/view/product.html"
        })
        .otherwise({
            redirectTo:'/'
        });
}]);

My simple dashboardController.js looks like this

var app = angular.module('docket');

    app.controller('DashboardController',['$scope, AuthFactory', function($scope, AuthFactory){

        console.log('dash controller');
        //console.log(AuthFactory);
    }]);

But when I am trying to run the app using loading the service DashboardController, I get his error. But if I remove the service from the controller dependency, there is no error. AuthFactory Error

3
  • use strick in app.module.js should be corrected to use strict. Commented Jan 26, 2015 at 4:25
  • @jason328 thanks for pointing out.. but unfortunately this doesn't solved the issue :( Commented Jan 26, 2015 at 4:28
  • 2
    DI argument list should not just be all one string, they should be separated by commas. Look at the error message clearly, It is looking for "$scope, AuthFactoryProvider". When you see any error switch to angular.js instead of angular.min.js so that you see more verbose error in the console. Commented Jan 26, 2015 at 4:31

1 Answer 1

2

Here is typo mistake " ' " after $scope

app.controller('DashboardController',['$scope, AuthFactory', function($scope, AuthFactory)

Change to

app.controller('DashboardController',['$scope', 'AuthFactory', function($scope, AuthFactory)
Sign up to request clarification or add additional context in comments.

3 Comments

Gahhh. You beat me by 1 minute.
Wonderful! It worked. I wasn't attentive enough to learn how to quote "'". Thanks.
WOW - I am not a novice Angular developer; and had spent 30 minutes trying to figure this out. In a last-minute-before-going-mad-moment, I decided to google... Your "fix" came up. I had ALSO missed out a single quote. Angular was failing silently (any good reason for it to be on mute? Surely it would have helped to cry a little!?!?!?!) Thank you!!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.