<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Angular.JS</id>
		<title>Angular.JS - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://logicwiki.co.uk/index.php?action=history&amp;feed=atom&amp;title=Angular.JS"/>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Angular.JS&amp;action=history"/>
		<updated>2026-06-06T19:28:09Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.26.2</generator>

	<entry>
		<id>http://logicwiki.co.uk/index.php?title=Angular.JS&amp;diff=525&amp;oldid=prev</id>
		<title>Dt1nh6: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Angular.JS&amp;diff=525&amp;oldid=prev"/>
				<updated>2016-05-09T13:27:40Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 13:27, 9 May 2016&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Dt1nh6</name></author>	</entry>

	<entry>
		<id>http://logicwiki.co.uk/index.php?title=Angular.JS&amp;diff=524&amp;oldid=prev</id>
		<title>Macrop at 20:20, 21 September 2015</title>
		<link rel="alternate" type="text/html" href="http://logicwiki.co.uk/index.php?title=Angular.JS&amp;diff=524&amp;oldid=prev"/>
				<updated>2015-09-21T20:20:08Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:MVC]]&lt;br /&gt;
[[Category:Javascript]]&lt;br /&gt;
[[Category:jQuery]]&lt;br /&gt;
&lt;br /&gt;
== Starting Up ==&lt;br /&gt;
&lt;br /&gt;
It can be used by just including script file. It does not have dependency.&lt;br /&gt;
 &amp;lt;script src=&amp;quot;angular.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;script src=&amp;quot;//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;script src=&amp;quot;//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Basic_Angular_MVC.png|thumbnail]]&lt;br /&gt;
=== Sample Angular Usage === &lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html ng-app&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
 &amp;lt;script src=&amp;quot;angular.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;script src=&amp;quot;controllers.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
 &amp;lt;div &amp;lt;b style=&amp;quot;color:red&amp;quot;&amp;gt;ng-controller='HelloController'&amp;lt;/b&amp;gt;&amp;gt;&lt;br /&gt;
 &amp;lt;input &amp;lt;b style=&amp;quot;color:red&amp;quot;&amp;gt;ng-model='greeting.text'&amp;lt;/b&amp;gt;&amp;gt;&lt;br /&gt;
 &amp;lt;p&amp;gt;&amp;lt;b style=&amp;quot;color:red&amp;quot;&amp;gt;{{&amp;lt;/b&amp;gt;greeting.text&amp;lt;b style=&amp;quot;color:red&amp;quot;&amp;gt;}}&amp;lt;/b&amp;gt;, World&amp;lt;/p&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
=== $location ===&lt;br /&gt;
In order to write to browser url $location can be used. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
function HelloController($scope, &amp;lt;b style=&amp;quot;color:red&amp;quot;&amp;gt;$location&amp;lt;/b&amp;gt;) {&lt;br /&gt;
 $scope.greeting = { text: 'Hello' };&lt;br /&gt;
 // use $location for something good here...&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== $scope ===&lt;br /&gt;
Aims the area between tags where  ng-coltroller attribute inserted&lt;br /&gt;
&lt;br /&gt;
=== $watch() ===&lt;br /&gt;
To update the field no matter how it gets updated, we want to use a $scope function called $watch()&lt;br /&gt;
&lt;br /&gt;
In this case, we want to watch &amp;lt;b style=&amp;quot;color:brown;&amp;quot;&amp;gt;funding.startingEstimate&amp;lt;/b&amp;gt; and call computeNeeded() whenever it changes. We could then rewrite the StartUpController to use this technique:&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
function StartUpController($scope) {  &lt;br /&gt;
  $scope.funding = { startingEstimate: 0 };&lt;br /&gt;
  computeNeeded = function() {&lt;br /&gt;
    $scope.funding.needed = $scope.funding.startingEstimate * 10;  &lt;br /&gt;
   };&lt;br /&gt;
  $scope.$watch('&amp;lt;b style=&amp;quot;color:brown;&amp;quot;&amp;gt;funding.startingEstimate&amp;lt;/b&amp;gt;', computeNeeded); } &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the expression to watch is in quotes. Yes, it is a string. This string is evaluated as something called an Angular expression.  &lt;br /&gt;
&lt;br /&gt;
=== ng-bind ===&lt;br /&gt;
To bind a cariable to a control &lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;p ng-bind=&amp;quot;greeting&amp;quot;&amp;gt;&amp;lt;/p&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ng-change ===&lt;br /&gt;
ng-change is used to fire a method when something change on control &lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;input ng-change=&amp;quot;&amp;lt;b style=color:green;&amp;quot;&amp;gt;computeNeeded()&amp;lt;/b&amp;gt;&amp;quot; ng-model=&amp;quot;funding.startingEstimate&amp;quot;&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
---------&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:js&amp;quot;&amp;gt;&lt;br /&gt;
function StartUpController($scope) {  $scope.funding = { startingEstimate: 0 };&lt;br /&gt;
  $scope.&amp;lt;b style=color:green;&amp;quot;&amp;gt;computeNeeded&amp;lt;/b&amp;gt; = function() {    $scope.needed = $scope.startingEstimate * 10;  }; } &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ng-repeat === &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;li ng-repeat='student in students'&amp;gt;    &amp;lt;a href='/student/view/{{student.id}}'&amp;gt;{{student.name}}&amp;lt;/a&amp;gt;  &amp;lt;/li&amp;gt; &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== ng-submit ===&lt;br /&gt;
If you have a form that groups inputs, you can use the ng-submit directive on the form itself to specify a function to call when the form submits. We can extend our previous example to let the user request funding for her startup by clicking a button: &lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;form ng-submit=&amp;quot;requestFunding()&amp;quot; ng-controller=&amp;quot;StartUpController&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ng-submit directive also automatically prevents the browser from doing its default POST action when it tries to submit the form. &lt;br /&gt;
&lt;br /&gt;
---------------------&lt;br /&gt;
'''For onclick, you’d use ng-click. For ondblclick, use ng-dblclick, and so on.''' &lt;br /&gt;
--------------------&lt;br /&gt;
&lt;br /&gt;
=== Shopping Cart Example ===&lt;br /&gt;
Let's see the code and then explain it line by line&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;html ng-app='myApp'&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
 &amp;lt;title&amp;gt;Your Shopping Cart&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body ng-controller='CartController'&amp;gt;&lt;br /&gt;
 &amp;lt;h1&amp;gt;Your Order&amp;lt;/h1&amp;gt;&lt;br /&gt;
 &amp;lt;div ng-repeat='item in items'&amp;gt;&lt;br /&gt;
 &amp;lt;span&amp;gt;{{item.title}}&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;input ng-model='item.quantity'&amp;gt;&lt;br /&gt;
 &amp;lt;span&amp;gt;{{item.price | currency}}&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span&amp;gt;{{item.price * item.quantity | currency}}&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;button ng-click=&amp;quot;remove($index)&amp;quot;&amp;gt;Remove&amp;lt;/button&amp;gt;&lt;br /&gt;
 &amp;lt;/div&amp;gt;&lt;br /&gt;
 &amp;lt;script src=&amp;quot;angular.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;script&amp;gt;&lt;br /&gt;
 function CartController($scope) {&lt;br /&gt;
 $scope.items = [&lt;br /&gt;
 {title: 'Paint pots', quantity: 8, price: 3.95},&lt;br /&gt;
 {title: 'Polka dots', quantity: 17, price: 12.95},&lt;br /&gt;
 {title: 'Pebbles', quantity: 5, price: 6.95}&lt;br /&gt;
 ];&lt;br /&gt;
 $scope.remove = function(index) {&lt;br /&gt;
 $scope.items.splice(index, 1);&lt;br /&gt;
 }&lt;br /&gt;
 }&lt;br /&gt;
 &amp;lt;/script&amp;gt;&lt;br /&gt;
 &amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following is a brief tour of what’s going on here. The rest of the book is dedicated&lt;br /&gt;
to a more in-depth explanation.&lt;br /&gt;
&lt;br /&gt;
Let’s start at the top:&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;html ng-app&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ng-app attribute tells Angular which parts of the page it should manage. Since we’ve&lt;br /&gt;
placed it on the &amp;lt;html&amp;gt; element, we’re telling Angular that we want it to manage the&lt;br /&gt;
whole page. This will often be what you want, but you might want to place it on a &amp;lt;div&amp;gt;&lt;br /&gt;
within the app if you’re integrating Angular with an existing app that uses other methods&lt;br /&gt;
to manage the page.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;body ng-controller='CartController'&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
In Angular, you manage areas of the page with JavaScript classes called controllers. By&lt;br /&gt;
including a controller in the body tag, I’m declaring that CartController will manage&lt;br /&gt;
everything between &amp;lt;body&amp;gt; and &amp;lt;/body&amp;gt;.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;div ng-repeat='item in items'&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ng-repeat says to copy the DOM inside this &amp;lt;div&amp;gt; once for every element in an&lt;br /&gt;
array called items. On every copy of the div, it will also set a property named item to the&lt;br /&gt;
current element so we can use it in the template. As you can see, this results in three&lt;br /&gt;
&amp;lt;div&amp;gt;s each, containing the product title, quantity, unit price, total price, and a button&lt;br /&gt;
to remove the item entirely.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;span&amp;gt;{{item.title}}&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
As we showed in the “Hello, World” example, data binding via {{ }} lets us insert the&lt;br /&gt;
value of a variable into part of the page and keep it in sync. The full expression&lt;br /&gt;
{{item.title}} retrieves the current item in the iteration and then inserts the contents&lt;br /&gt;
of that item’s title property into the DOM.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;input ng-model='item.quantity'&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
The ng-model definition creates data binding between the input field and the value of&lt;br /&gt;
item.quantity.&lt;br /&gt;
&lt;br /&gt;
The {{ }} in the &amp;lt;span&amp;gt; sets up a one-way relationship that says “insert a value here.”&lt;br /&gt;
We want that effect, but the application also needs to know when the user changes the&lt;br /&gt;
quantity so it can change the total price.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We’ll keep changes in sync with our model by using ng-model. The ng-model declaration&lt;br /&gt;
inserts the value of item.quantity into the text field, but it also automatically updates&lt;br /&gt;
item.quantity whenever the user types a new value.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;span&amp;gt;{{item.price | currency}}&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span&amp;gt;{{item.price * item.quantity | currency}}&amp;lt;/span&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We want the unit price and total price to be formatted as dollars. Angular comes with&lt;br /&gt;
a feature called '''filters''' that lets us transform text, and there’s a bundled filter called&lt;br /&gt;
currency that will do this dollar formatting for us. We’ll look at filters more in the next&lt;br /&gt;
chapter.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 &amp;lt;button ng-click='remove($index)'&amp;gt;Remove&amp;lt;/button&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This allows users to remove items from their carts by clicking a Remove button next to&lt;br /&gt;
the product. We’ve set it up so that clicking this button calls a remove() function. We’ve&lt;br /&gt;
also passed in $index, which contains the iteration number of the ng-repeat, so we&lt;br /&gt;
know which item to remove.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 function CartController($scope) {&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
This CartController manages the logic of the shopping cart. We’ll tell Angular that&lt;br /&gt;
the controller needs something called $scope by putting it here. '''The $scope is what lets&lt;br /&gt;
us bind data to elements in the UI.'''&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 $scope.items = [&lt;br /&gt;
  {title: 'Paint pots', quantity: 8, price: 3.95},&lt;br /&gt;
  {title: 'Polka dots', quantity: 17, price: 12.95},&lt;br /&gt;
  {title: 'Pebbles', quantity: 5, price: 6.95}&lt;br /&gt;
 ];&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
By defining $scope.items, I’ve created a dummy data hash to represent the collection&lt;br /&gt;
of items in the user’s shopping cart. We want to make them available to data bind with&lt;br /&gt;
the UI, so we’ll add them to $scope.&lt;br /&gt;
Of course, a real version of this can’t just work in memory, and will need to talk to a&lt;br /&gt;
server to properly persist the data. We’ll get to that in later chapters.&lt;br /&gt;
&amp;lt;pre class=&amp;quot;brush:html&amp;quot;&amp;gt;&lt;br /&gt;
 $scope.remove = function(index) {&lt;br /&gt;
  $scope.items.splice(index, 1);&lt;br /&gt;
 }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
We want the remove() function available to bind in the UI, so we’ve added this to $scope&lt;br /&gt;
as well. For the in-memory version of the shopping cart, the remove() function can just&lt;br /&gt;
delete items from the array. Because the list of &amp;lt;div&amp;gt;s created by ng-repeat is data&lt;br /&gt;
bound, the list automatically shrinks when items disappear. Remember, this remove()&lt;br /&gt;
function gets called from the UI whenever the user clicks on one of the Remove buttons.&lt;/div&gt;</summary>
		<author><name>Macrop</name></author>	</entry>

	</feed>