Re:Practical AngularJS Examples
by bsaul on Sunday September 01, 2013 @05:41AM
(#6309681)
Anyone got a post on how to structure big angular apps ?
i've been struggling a bit with menu bars : it seems to me that you can't prevent copy/pasting the menu bars on each of your screens if you want to keep meaningfull URLs (as the routing component only maps a url to a single controller).
Works fine, as long as your URL scheme structured enough. Toss me your email, and I can give you the controller and the tmeplate code with link to the live site. I would have copy-pasted here but don't want to turn HN into stackoverflow.
Re:Practical AngularJS Examples
by mbell on Sunday September 01, 2013 @10:29AM
(#6310490)
Put your menu bar code in your 'master' template (wherever you're defining the location for your ng-view). Use a separate Nav controller for the menu bar.
It seems like your biggest issue is just data sharing, e.g. each page needs different menu items or something. Just create an Angular service that provides the backing data for the menu bar and exposes an API to other controllers to change things in the menu bar or get the value of a search field in the menu bar, etc. This type of thing is exactly what angular services are for.
I'm not sure I would classify this as a "big" app, but it has four tabs and is slowly growing in functionality. The menu bar (and highlighting) is a very simple controller and service.
Obligatory disclaimer: I'm by no means an angular expert.
Re:Practical AngularJS Examples
by diggan on Sunday September 01, 2013 @06:41AM
(#6309775)
Use common sense. First step, having the files in one folder. Everything mixed up. You move into a structure of seperating services from directives, controllers from filters and so on. But the way most people seems to be doing it (the Angular way™) when it comes to the bigger applications is by splitting it up by functionality/modules. So you have a forum and therefore probably at least 3 different modules, "thread", "user" and "forum" or something similar. Just follow the MVC pattern with whatever filestructure that works with you and your team.
Copy/pasting the menu bars? For that, I would have a directive which controls the display of the menu and acting accordingly. Only when declaration is needed and it's reusable. I don't understand your point about meaningful urls though, they are as meaningful as you make them.
Re:Practical AngularJS Examples
by bsaul on Sunday September 01, 2013 @08:17AM
(#6310069)
well using a directive means you still have to put it everywhere ( in all your views). i'm more used to something like a master template with global menus and a content div. but for that you would need multiple ng-views or something similar, since my menu bars also need to be linked to the context.
Re:Practical AngularJS Examples
by kops on Sunday September 01, 2013 @08:27AM
(#6310098)
As for the structure, I tried Yeoman but quickly gave up due to learning curve and lack of time. I settled on a simple folder structure with minimal grunt file which uglifies and minifies my code. If minification/uglification wasn't a concern then I would have ditched grunt too. Not because I have issues with these cool tools, but purely because I just don't have time to understand them thoroughly.
AngularJS itself helped fix my jQuery spaghetti wonderfully though.
Re:Practical AngularJS Examples
by chrisrhoden on Sunday September 01, 2013 @08:27AM
(#6310095)
You can listen for the $routeChangeSuccess event from outside of your ng-view. You can attach arbitrary key=> value pairs to your routes to annotate them in ways that are particular to your app.
Re:Practical AngularJS Examples
by sararob on Sunday September 01, 2013 @11:07AM
(#6310647)
If you want to add a backend to your Angular app, check out AngularFire. Here's the quickstart guide and tutorial: http://angularfire.com/quickstart.html
Re:Practical AngularJS Examples
by Kiro on Sunday September 01, 2013 @10:50AM
(#6310575)
I don't understand why a custom filter is needed in "4. Instant Search". I thought "<li ng-repeat="i in items | filter:searchString">" did the same thing.
Re:Practical AngularJS Examples
by dexterbt1 on Monday September 02, 2013 @01:38PM
(#6316162)
I recently viewed a few of their videos and I find them too short, seemingly lacking. It might depend on the audience though. In my case, a little theory and architectural overview works better, and the official docs cover this well enough.
i've been struggling a bit with menu bars : it seems to me that you can't prevent copy/pasting the menu bars on each of your screens if you want to keep meaningfull URLs (as the routing component only maps a url to a single controller).
Works fine, as long as your URL scheme structured enough. Toss me your email, and I can give you the controller and the tmeplate code with link to the live site. I would have copy-pasted here but don't want to turn HN into stackoverflow.
Disclaimer: I am no frontend/javascript developer. Just getting by.
It seems like your biggest issue is just data sharing, e.g. each page needs different menu items or something. Just create an Angular service that provides the backing data for the menu bar and exposes an API to other controllers to change things in the menu bar or get the value of a search field in the menu bar, etc. This type of thing is exactly what angular services are for.
https://github.com/polyfractal/elasticsearch-inquisitor
I'm not sure I would classify this as a "big" app, but it has four tabs and is slowly growing in functionality. The menu bar (and highlighting) is a very simple controller and service.
Obligatory disclaimer: I'm by no means an angular expert.
Copy/pasting the menu bars? For that, I would have a directive which controls the display of the menu and acting accordingly. Only when declaration is needed and it's reusable. I don't understand your point about meaningful urls though, they are as meaningful as you make them.
If you're looking for general app structure tips then the Angular generator for Yeoman is a good place to start.
Hope this helps, let me know if it is unclear.
Post author (Martin Angelov) said that he built it himself on Ace, however it doesn't seem to be OS.
http://www.yearofmoo.com/2012/08/use-angularjs-to-power-your...
http://www.yearofmoo.com/2012/10/more-angularjs-magic-to-sup...
Not like todomvc which is supposed to be for beginners yet have almost no comments...
https://github.com/tastejs/todomvc/blob/gh-pages/architectur...
What's the definition of truthful?