Iman Memarpour Iman Memarpour - 3 months ago 13
AngularJS Question

AngularJS Factory using Visual Studio Snippet

I Have this AngularJS factory that's is working fine, However when i try to accommodate it in auto generated visual studio snippet for AngularJS factory, It does not happen and i can not get the syntax right.This is my factory

angular.module('payrollApp').factory('countries', function ($http) {
return {
getCountries: function (callback) {
$http.get('countries.json').success(callback);
}
}});


But how should i change it so i can use Visual Studio auto generated code. This is the auto generated snippet:

(function () {
'use strict';

angular
.module('app')
.factory('factory', factory);

factory.$inject = ['$http'];

function factory($http) {
var service = {
getData: getData
};

return service;

function getData() { }
}})();

Answer

Try this,

(function () {
    'use strict';
    angular
        .module('payrollApp')
        .factory('countries', factory);
    factory.$inject = ['$http'];
    function factory($http) {
        var service = {
            getCountries: getCountries
        };
        return service;
        function getCountries(callback) {
      $http.get('countries.json').success(callback);          
     }
    }})();
Comments