Answer the question
In order to leave comments, you need to log in
How to preload models for AngularJS?
There is such a thing for Backbone - backbonejs.ru/#FAQ-bootstrap
And what is the right way to do it for angular?
There is an ngInit directive, but it was not particularly recommended on stackoverflow, they say it is not accepted. Yes, and it doesn’t come out very beautifully, the syntax is inconvenient.
Answer the question
In order to leave comments, you need to log in
What about the ng-init directive? In your example, there is no such thing at all.
The data should not be stored in the template, that is, in the attributes in the form of text, so that you would then have to parse it manually. If you carefully look at what will be the output of the example you have given, you will see the following:
Let's say our collection will look like
then the user will receive the following html stuff:
<script>
var accounts = new Backbone.Collection;
accounts.reset([{id: 1, username: 'foo'}, {id: 2, username: 'bar'}]);
</script>
<script>
angular.module('prefetchedData', [])
.constant('users', <%= @accounts.to_json %>)
.constant('projects', <%= @projects.to_json(:collaborators => true) %>);
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question