简体   繁体   中英

Can you use AngularJS with Rails Models

If the title question is unclear, let me clarify. Though the question is conceptual, rather than physical.

I have a rails application with a few models (order, buyer). I recently discovered angularjs and noticed that it is a very powerful tool, however, I, obviously, would not like to convert my project.

I'm particularly interested in the data-binding of angular, aka how the info of views can be instantly updated (without page reload). So, is there a way to use angular but take the data from the rails model, instead of the angular model?

If this isn't possible, feel free to comment with a different way to go about this.

Here's what a move to Angular with Rails would mean to me.

  • Rails does not do any server side HTML templating.
  • Your web server serves static files - HTML (angular views), CSS, and JavaScript.
  • Rails serves an API (your Rails models being serialized to JSON).
  • There isn't really a model to recreate on the Angular side. You get JavaScript objects back from the web API calls. Controllers, Services, and Directives do a lot of the work in Angular.
  • You choose when to send requests to the server in Angular. Update whenever your app needs to.

I think it's helpful to think of your Angular app like any other client of your Rails API.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM