myself
myself

Reputation: 405

My Angular app only works with a certain syntax

I'm following a thinkster tutorial on angular and rails. The tutorials says to make the app like this...

angular.module('flapperNews', [])

with the controllers and factories like this...

.config([... .controller([... .factory([...

and so on. However it only works when I do this...

var flapperNews = angular.module('flapperNews', [])

with the controllers and factories like this...

flapperNews.config([... flapperNews.controller([... flapperNews.factory([...

Is there a short answer for this? Is the tut wrong or am I doing something wrong. Here is the tut link https://thinkster.io/angular-rails#introduction

I haven't started the rails part yet, just wanted to know why it breaks.

Here are the two codepens... This one works as described above. http://codepen.io/MrNagoo/pen/regKgM

This one fails and gives errors, although it's how i'm being directed to write the code...

http://codepen.io/MrNagoo/pen/regKEM

Upvotes: 1

Views: 44

Answers (2)

adrianolsk
adrianolsk

Reputation: 332

Your problem is that you are using ; before doing the next .config this terminate the statement. You need to chain the components.

angular.module("app",[]) .config() .controller() .service();

here is the codepen with the working code

But you should definettly follow John Papa's style guide

Upvotes: 0

John Smith
John Smith

Reputation: 2341

I would suggest looking at John Papa's style guide: https://github.com/johnpapa/angular-styleguide/tree/master/a1

You create your module as you said:

angular.module('flapperNews', [])

And you add a controller/factory/config/whatever like:

angular
    .module('flapperNews')
    .config(config)

function config() { ... }

Upvotes: 1

Related Questions