Dave Scott
Posts: 0
Joined: Tue Oct 09, 2012 11:24 am

How To Deploy Angular Service

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

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

How To Deploy Angular Service

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

Return to “Issues”