cnian cnian - 1 month ago 12
AngularJS Question

using angular service on ionic framework

(function () {
'use strict';

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

UserService.$inject = ['$http'];
function UserService($http) {
var service = {};

service.GetAll = GetAll;
service.GetById = GetById;
service.GetByUsername = GetByUsername;
service.Create = Create;
service.Update = Update;
service.Delete = Delete;

return service;


How can I write this service on ionic framework in services.js. can I use exactly the same or should I change something in syntax?

Answer

Well you can name it anything as you have service.js but it is in angular term a factory.

An angular service has syntax like

app.service('hexafy', function() {
    this.myFunc = function (x) {
        return x.toString(16);
    }
});

And to answer your question yes you can use it just have to close the opening brackets in the above syntax

(function () {
   'use strict';

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

UserService.$inject = ['$http'];
function UserService($http) {
    var service = {};

    service.GetAll = GetAll;
    service.GetById = GetById;
    service.GetByUsername = GetByUsername;
    service.Create = Create;
    service.Update = Update;
    service.Delete = Delete;

    return service;
   }
})

hope it helps.