Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKirsty Pollock
14,261 PointsMy way - any disadvantages?
I went a slightly different structural route with this, that I think is more flexible, and clearer, but I would like to know if there are any disadvantages that I did not consider...
My app ended up as:
angular.module('todoListApp', [])
.controller("mainController", mainController)
.service("dataService", dataService);
and the controller/service as named functions
function mainController($scope, dataService)
{
...
My natural style (in other languages) is that the controllers and services should be independent and the app should decide which to load (possibly at runtime, possibly config dependent... that kind of thing). Of course here in js you can't declare the interface that you expect dataService / mainController to expose - which would normally be my approach (or maybe there is a way??)
2 Answers
Thomas Nilsen
14,957 PointsThis guide is, in my opinion, fantastic.
It's shows best practices, what you'd want to avoid and so on...
It's also endorsed by the Angular team
Thomas Nilsen
14,957 PointsThe guide I gave you mentions this as well, but check it out if you want.
I'ts about avoiding scope unless it's absolutely necessary.
$scope will ( as far as I know) be gone in Angular 2.0
Kirsty Pollock
14,261 PointsKirsty Pollock
14,261 PointsThanks for that. I note that they do not address my particular question per se, in that they recommend separate files (I agree for the same reasons), and their example also puts the declaration of the linkages between directive/controller/service in the directive/controller/service itself (like the video and unlike me) - but that they provide no rationale therefor, only for the split into files.
If I decide/end up having to do any significant amount of Angular, then I'll go dig on the web, for further rationale - but it may be a matter of taste, or a matter of implications (e.g. for dependencies or scoping) of which I am not yet aware.
Cheers for the link, most useful.