R
R
Rrooom2014-09-06 20:30:13
Django
Rrooom, 2014-09-06 20:30:13

Is it possible to teach Angular to take default values ​​from the page?

Angular is a nice thing, but support for working without js is often required.
Now a project has come into my hands for revision, a typical block looks like this:

<article data-ng-bind="article.text" data-ng-init="article.text='{{ object.text }}'">{{ object.text }}</article>

<input type="text" data-ng-model="article.name" data-ng-init="article.name='{{ form.instance.name }}'" value="{{ form.instance.name }}">

(don't be confused by the brackets, this is django template engine, angular has {$$}
) the page is simply loaded with data - it is available to both search engines and people without js. But it doesn't look pretty to me. Firstly, duplication of data - and the weight is growing, and you can make a mistake. Secondly, everything breaks periodically, because of the contents of data-ng-init - some quotes and it's all over (for this there are a bunch of filters that screen different types of values ​​- for text, arrays, bools).
Is it possible to teach angular like this:
<article data-ng-bind="article.text">{{ object.text }}</article>

<input data-ng-model="article.name" value="{{ form.instance.name }}">

What would he take after loading and write down the contents of the tag he is associated with in article.text?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kamilgarey, 2014-09-11
@kamilgarey

You are trying to find an implementation of a solution that, like solving the problem of a page without JS, is "crooked".
You see, JS MV* is just designed to not collect data from the page, as is usually done with jQuery, to abstract from data representations and focus on logic. Therefore, even if there is a solution you need, it is essentially crutches.
There is a more beautiful and functional solution for your problem. For cases when it is necessary to issue pages without JS, a proxy is used that does the browser's job of displaying. For example PhantomJS .
The following links will be useful for supporting search engines:
SEO for single page applications - Backbone.js Tut...
Getting Started - Webmasters - Google Developers
Indexing AJAX sites — Yandex.Help. Webmaster

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question