RequireJs + AngularJs + Controller + Express - Router

168 views
Skip to first unread message

Rodrigo F.

unread,
Jan 7, 2014, 11:42:24 PM1/7/14
to ang...@googlegroups.com
 Hi Guys,
 I'm doing an app with requirejs, angularjs and express, so my page will be render direct by express, i'm not needing at the moment to use the router from angularjs, my question is how i bind my controller with html element? I'm using RequireJs that's why i can't just put the directly the directives from angularjs in my html...
  

Daniel Tabuenca

unread,
Jan 8, 2014, 12:20:20 AM1/8/14
to ang...@googlegroups.com
I'm not sure why using RequireJS would change where you put the directives in the html. Could you elaborate a bit?

Samuel Ytterbrink

unread,
Jan 8, 2014, 7:18:33 AM1/8/14
to ang...@googlegroups.com
Are you referring to the first directive? the ngApp?

This tutorial should work for you.

Message has been deleted

Rodrigo F.

unread,
Jan 8, 2014, 10:34:50 AM1/8/14
to ang...@googlegroups.com
Daniel Tabuenca, 

 As far i know, when you use requirejs + angularjs you can't use angular directives directly in the html, you have to put it in the background code, like in the route, but like i said before my page will be render directly from expressjs, so how i bind my html element with angular controller using requirejs without using angular router?

Rodrigo F.

unread,
Jan 8, 2014, 10:37:55 AM1/8/14
to ang...@googlegroups.com
Samuel Ytterbrink,

 I've seen this tutorial before and they just bind the angular controller with html through angular route.

Samuel Ytterbrink

unread,
Jan 8, 2014, 11:45:30 AM1/8/14
to ang...@googlegroups.com
I think you confuse your self with 2 different things.

The only thing that changes when using Requirejs and/or any other AMD module-system is that you need to manualy bootstrap angular.

You need to make sure that all the angular code are loaded before this (you can use Requirejs domready and its dependency system). Then you just run angular.bootstrap(<element>, "<module_name>") and your good to go. This is instead of using the ng-app directive on the element you use as element root for the application.

If you cant use directives after this in your application then its not that you use Requirejs that is the problem. And for us to be able to help you in that case you need to give us more info about your application.

PS. your backend have nothing to do with this problem.


2014/1/8 Rodrigo F. <fonse...@gmail.com>
Samuel Ytterbrink,

 I've seen this tutorial before and they just bind the angular controller with html through angular route.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/O6MtAWnPJuQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/groups/opt_out.



--
Samuel Ytterbrink

Rodrigo F.

unread,
Jan 8, 2014, 12:08:19 PM1/8/14
to ang...@googlegroups.com
Ok, i think i'm confused(i'm using angular just in 2 days...), i know that i need to manually bootstrap angular and i did that, so one question, using requirejs can i use directives like ng-controller in my html element?  And another question, angular routers work with express? Or they are just used to single web app and work with expresses through ajax? Because i want to use router, but the client have to connect with server directly and refresh the page...

Samuel Ytterbrink

unread,
Jan 8, 2014, 2:52:37 PM1/8/14
to ang...@googlegroups.com
Yes!

You can use directives as if you where using any other way of loading your scripts. Though make sure you have loaded them all before you bootstrap the application.

I don't fully understand your design. But the basics are that you don't need the router if you are not doing a one-page-app. But basically you could have many pages with there own mini router to only manage a small set of views.

If i where you i would ask myself:
 * How are my app going to be used.
 * What type of server are im going to write with express (great choice btw).
 * What things can i do without.

It seams to me that you have started with way to many unfamiliar technologies at one same time.

It might help you to configure express to only serve static content and build a prototype with only static pages and the angular router. It will be enough to get a feel for angular and what you want to build. Then you can pick a path from there. To load new pages or json form express.

When having such a amazing back-end it sounds to me a little loony to not send data as json and serve static html (angular templates). The only strong argument against it that I see is that its harder to make a page like that index correctly for a search engine crawler.

And if you can remove anything from your stack in a first attempt, do so!


2014/1/8 Rodrigo F. <fonse...@gmail.com>



--
Samuel Ytterbrink
Message has been deleted

Rodrigo F.

unread,
Jan 8, 2014, 3:42:12 PM1/8/14
to ang...@googlegroups.com
  I'm using node.js + express(server side) and angularjs + requirejs(client side) and i understood everything about what you said Samuel, thanks for your help.

Reply all
Reply to author
Forward
0 new messages