Page 1 of 1

How To Deploy Angular Service

Posted: Wed Aug 05, 2015 7:35 am
by Dave Scott

Hi,

I'm looking to persist data across multiple page views, and it seems that the 'correct' way to do this with angular is to create an angular service to store the data and then inject the service into all of the controllers that will need access to the data. Per here: http://stackoverflow.com/questions/14...

I can see that we can now create custom directives and have managed to get this to work.

However, I can't see how to create and deploy custom angular services and then to inject them into the various controllers so that the service / data is available from other views?

Please advise how I should do this?

Many thanks,
Dave


How To Deploy Angular Service

Posted: Thu Aug 13, 2015 2:48 pm
by Serhii Kulibaba

Hello Dave,

You can create generic service (with custom JS implementation), create it's singleton, which sends request, each time the function codeApperyio.get('serviceName')/code is called it returns the same singleton.

codeApperyio.get('serviceName')/code returns the same data on any screen, which function func() returned before
pre
define( ['require'], function( require ){
return [{
/* name for angular resource /
name: 'javaScript1',
/ type of angular resource [factory, filter, service] /
type: 'service',
/ angular dependency injection array */
deps: [ 'Apperyio', func ]
}];
function func( Apperyio ){
};
});/pre