<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://luminoussheep.net/mediawiki/index.php?action=history&amp;feed=atom&amp;title=AngularJS</id>
	<title>AngularJS - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://luminoussheep.net/mediawiki/index.php?action=history&amp;feed=atom&amp;title=AngularJS"/>
	<link rel="alternate" type="text/html" href="https://luminoussheep.net/mediawiki/index.php?title=AngularJS&amp;action=history"/>
	<updated>2026-04-16T20:37:57Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.8</generator>
	<entry>
		<id>https://luminoussheep.net/mediawiki/index.php?title=AngularJS&amp;diff=87&amp;oldid=prev</id>
		<title>Martin: Created page with &quot;= App = &lt;pre&gt;  &lt;html ng-app=&quot;notesApp&quot;&gt;    angular.module(&#039;notesApp&#039;, []) &lt;/pre&gt;  = Services Object = &lt;pre&gt; function ItemObjectService() { 	var items = [ 	{id: 1, label : &#039;Ite...&quot;</title>
		<link rel="alternate" type="text/html" href="https://luminoussheep.net/mediawiki/index.php?title=AngularJS&amp;diff=87&amp;oldid=prev"/>
		<updated>2021-09-14T21:41:08Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;= App = &amp;lt;pre&amp;gt;  &amp;lt;html ng-app=&amp;quot;notesApp&amp;quot;&amp;gt;    angular.module(&amp;#039;notesApp&amp;#039;, []) &amp;lt;/pre&amp;gt;  = Services Object = &amp;lt;pre&amp;gt; function ItemObjectService() { 	var items = [ 	{id: 1, label : &amp;#039;Ite...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;= App =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 &amp;lt;html ng-app=&amp;quot;notesApp&amp;quot;&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 angular.module(&amp;#039;notesApp&amp;#039;, [])&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Services Object =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
function ItemObjectService() {&lt;br /&gt;
	var items = [&lt;br /&gt;
	{id: 1, label : &amp;#039;Item 1&amp;#039;},...];&lt;br /&gt;
	this.list = function() {&lt;br /&gt;
		return items;&lt;br /&gt;
	};&lt;br /&gt;
	this.add = function(item) {&lt;br /&gt;
		items.push(item);&lt;br /&gt;
	};&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.service(&amp;#039;ItemObjectService&amp;#039;, [ItemObjectService]&lt;br /&gt;
 // service - for classes OO style&lt;br /&gt;
);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
= Services functional =&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
.factory(&amp;#039;ItemService&amp;#039;, function() {&lt;br /&gt;
	// factory - functional/return functoins/objects&lt;br /&gt;
        // no self/this as this is functional not object?&lt;br /&gt;
	var items = [&lt;br /&gt;
	{id: 1, label : &amp;#039;Item 1&amp;#039;},...];&lt;br /&gt;
	return {&lt;br /&gt;
		list: function() {&lt;br /&gt;
			// Why not self.items or this.items?&lt;br /&gt;
			return items;&lt;br /&gt;
		},&lt;br /&gt;
		add: function(item) {&lt;br /&gt;
			items.push(item);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
})&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
= Promises =&lt;br /&gt;
can chain:&lt;br /&gt;
&lt;br /&gt;
$http.get(&amp;quot;/foo&amp;quot;).then(function(response) { }, function(errro) { } ).then(S, E).then(S, E)...&lt;br /&gt;
&lt;br /&gt;
error handling propagates can put common error handling at the end.&lt;br /&gt;
&lt;br /&gt;
==$q service==&lt;br /&gt;
* var deferredObj = $q.defer() - create own promises&lt;br /&gt;
* $q.deferredObj.resolve(&amp;#039;&amp;#039;successData&amp;#039;&amp;#039;) - resolve deferredObj with &amp;#039;&amp;#039;successData&amp;#039;&amp;#039;&lt;br /&gt;
* $q.deferredObj.reject(&amp;#039;&amp;#039;failureData&amp;#039;&amp;#039;) - resolve deferredObj with &amp;#039;&amp;#039;failureData&amp;#039;&amp;#039;&lt;br /&gt;
* $q.reject(&amp;#039;&amp;#039;rejectData&amp;#039;&amp;#039;) - from within a promise (success or failure) - continue to next error handler with &amp;#039;&amp;#039;rejectData&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
= $http =&lt;br /&gt;
can supply just url or put the url and method on the config and use $http(config)&lt;br /&gt;
* $http.get(url, config)&lt;br /&gt;
* $http.post(url, data, config)&lt;br /&gt;
* $http.put(url, data, config)&lt;br /&gt;
* $http(config)&lt;br /&gt;
&lt;br /&gt;
config:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
method&lt;br /&gt;
url&lt;br /&gt;
params [{key: &amp;#039;value&amp;#039;, key2: &amp;#039;value2&amp;#039;}] // value objects converted to json&lt;br /&gt;
data {}&lt;br /&gt;
headers {&amp;#039;Content-Type&amp;#039;: &amp;#039;text/csv&amp;#039;}&lt;br /&gt;
xsrfHeaderName - cross site request forgery &lt;br /&gt;
xsffCookieName - name of cookie in xsrf handshake&lt;br /&gt;
cache : true/false or cache object - if true angular caches responses&lt;br /&gt;
transformRequest: function(data, headers){} &lt;br /&gt;
transformResponse: &lt;br /&gt;
timeout: // time or promise object that on reject timesout the call&lt;br /&gt;
withCredentials: true/false&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Martin</name></author>
	</entry>
</feed>