For a GameJam I'm trying to code a simple web-based text adventure game with sprites and small animations in AngularJS. I'm a little new to Angular and am having some trouble figuring out how to structure it. I think my trouble comes from my struggle with Controllers vs Directives.

My game essentially needs to pull text from a text file and display it within a DOM element when clicked. Accompanying that is a separate DOM item that displays a character sprite image. When certain bits of text are displayed, the image needs to animate.

Can anyone who knows AngularJS well walk me through the most clean and efficient way to structure this between my controllers, directives, and the HTML view?

closed as too broad by Robert Harvey, Jules, TMN, TZHX, gnat Jul 1 '16 at 0:25

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


I think you should use directives for the DOM elements and controllers for interaction between these directives. DOM manipulation should only be done inside a directive.

Fetching a text file could be done inside the controller, but it would be better if you did that through a service. Services can be used for reusable business logic/fetching data.

You could see it as the MVC pattern. Model/business-logic can be put in a service, View is composed of normal HTML elements and directives and the Controller who orchestrates communication between the two.

Not the answer you're looking for? Browse other questions tagged or ask your own question.