lathonez / clicker

Ionic 2 + @angular/cli Seed Project : Angular2 + Typescript + Karma + Protractor + Travis
http://lathonez.com/2018/ionic-2-unit-testing/
MIT License
430 stars 137 forks source link

Question: The purpose of components.module.ts? #245

Closed CoreyCole closed 7 years ago

CoreyCole commented 7 years ago

I'm trying to model my ionic project after this one and I'm trying to understand every piece of it.

What is the purpose of src/components/components.module.ts? Ionic doesn't generate this automatically when creating components and I'm wondering what it's used for.

Also, while I'm asking, what is the purpose of src/components/index.ts?

Thanks so much for making this repository lathonez, it's been helping my team a lot. Also thanks to anyone who answers my questions :)

CoreyCole commented 7 years ago

Also

Sorry for all these questions at once. I hope they're not too uninformed.

lathonez commented 7 years ago

Hey Corey,

You'll get quicker (and better) general programming answers on stack overflow. But I am happy enough to point you at documentation.

1 - What is the purpose of src/components/components.module.ts

It is an angular 2 module for the components in clicker: https://angular.io/docs/ts/latest/guide/ngmodule.html

2 - Also, while I'm asking, what is the purpose of src/components/index.ts?

It is a barrel, it allows easier imports. Barrels were more relevant pre-modules. https://basarat.gitbooks.io/typescript/docs/tips/barrel.html

3 - do you suggest not using the ionic-cli at all?

Use it for everything it is capable of doing. Ionic don't support testing at all, so you need to use ng-cli for that

4 - I noticed that your pages don't have "Page" appended as a suffix

Pages are just components in angular 2, they used to be different (Ionic used to have an @Page annotation), but they don't anymore. Where possible, my code follows the angular 2 style guide: https://angular.io/styleguide

5 - why does ionic-cli automatically add components to src/app/app.module.ts in the declarations array when it doesn't do the same for pages?

No idea - a question for Ionic?

6 - what does ... mean

It expands the array: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator

Thanks