Another Salesforce blog!!!

Salesforce, Apex

Creating Factory in AngularJS


'use strict';
/* Application Service */
angular
.module('appname')
.factory('$application', function($resource, $response, $path) {

var $application = $resource(
$path.rest + '/rest/application/:method',
{ },
{
all: {
method: 'GET',
isArray: true,
transformResponse: function(data, header) {
return $response.to_resource(data, $application);
}
}
});

$application.prototype.$options = function(){

}

return $application;
});

[/cc]

here is how you will access your newly created factory:

[cc]

angular
.module('appname')
.controller('application.create',
function($scope, $location, $storage, $application){

/* get dropdown data */
$application.get({ method: 'types' }, function( types ){
$scope.dropdown = types;
});

});

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*