1

I'm reading the book Angularjs Essentials - http://www.goodreads.com/book/show/23139559-angularjs-essentials

I'm trying to follow the code exmaples.

I have this plunker with the code I have

https://plnkr.co/edit/jFK3ooODMChtXJqO7syf?p=preview

locally in chrome I get the error

    Error: ng:areq
    Bad Argument

    Argument 'parkingCtrl' is not a function, got undefined

I'm sure the problem is syntax in 'angular module' bit at the top of either controller.js, services.js or directive.js

Can anyone see what I'm doing wrong or how the stop this error

1
  • You can check the answer below Commented Dec 7, 2016 at 13:44

2 Answers 2

3

When you define your service, you had recreated the app again with this syntax angular.module('parking', []) that's why the defined controller is no longer existing after this file loaded. So you can change this to angular.module('parking') as below in services.js file will fix the issue

angular.module('parking').factory("parkingService", function() {
    var _calculateTicket = function (car) {
        var departHour = new Date().getHours();
        var entranceHour = car.entrance.getHours();
        var parkingPeriod = departHour - entranceHour;
        var parkingPrice = parkingPeriod * 10;
        return {
            period: parkingPeriod,
            price: parkingPrice
        };
    };
    return {
        calculateTicket: _calculateTicket
    };
});
Sign up to request clarification or add additional context in comments.

Comments

0

There are two issues

(i) Change the references as below in plunker

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular-route.js"></script>

(ii) No need to have dependencies injected for the service parkingService, change it as

angular.module('parking').factory("parkingService", function() {
}

DEMO

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.