Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding Two-Way Data-Binding in AngularJS
    primarykey
    data
    text
    <p>I'm new to AngularJS. A long time I tried to abuse it the way I've always used Javascript-Frameworks like JQuery or Mootools. Now I understood that it's not gonna work like that anymore... But I've come across some big problems since I always generate my HTML-output with a CMS.</p> <p>So it's pretty static, when it first comes out... Small example:</p> <pre><code>&lt;ul&gt; &lt;li&gt;foo &lt;span&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;li&gt;bar &lt;span&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;li&gt;blub &lt;span&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>Now I thought, that Two-Way Databinding means I can generate the View with help of the Angular Scope and Controller, but also can generate Models by the View.</p> <p>I may got something confused there... So here's my question. Is there any way to initiate Models from static HTML-output from a CMS?</p> <p>I tried something like this...</p> <pre><code>&lt;ul ng-controller="Ctrl"&gt; &lt;li ng-init="item[0].name=foo"&gt;{{item[0].name}} &lt;span ng-click="remove(0)"&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;li ng-init="item[1].name=bar"&gt;{{item[1].name}} &lt;span ng-click="remove(1)"&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;li ng-init="item[2].name=blub"&gt;{{item[2].name}} &lt;span ng-click="remove(2)"&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And in my controller I wrote a delete function. But when it did delete, it did only delete the name... the span-button was still there</p> <p>It did work though when I defined my data as an javascript-array and did the whole output via Angular with ng-repeat... like this:</p> <pre><code>&lt;ul ng-repeat="it in item"&gt; &lt;li&gt;{{it.name}} &lt;span ng-click="remove($index)"&gt;delete&lt;/span&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I hope I made a point here and everyone get's my dificulty and problems? Can anyone tell me if what I was trying there is possible at all?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload