-2

I am working on Ionic Framework and there is a requirement that I need to inject the angular services in controller to get the data or perform any CRUD operation in backend. Please Let me know how I can do this?

3
  • 1
    stackoverflow.com/questions/16876748/… look here Commented May 3, 2016 at 10:40
  • Have you got any sample code or any attempts to show us? Commented May 3, 2016 at 10:44
  • Thanks Mohan.. Its working for me.. Commented May 3, 2016 at 11:14

3 Answers 3

0

if you are using Ionic2 here is an example on how to inject a Service into a controller; note the @Injectable decorator in the Service, the [providers] parameter of the @Page decorator in the Controller, and how the service instance is a parameter of the constructor.

Sign up to request clarification or add additional context in comments.

Comments

0

Ionic Framework is build upon angular.js, so there s no difference in doing this in Ionic.

Its simple like

var myapp = angular.module('myApp',['ionic']);

myapp.service('MyService',['$http', function($http) {
   return {
       doSomeThing: function() {
           // do something here with $http or whatever
       },
       doSomeThingElse: function() {
       }
}
]);

myapp.controller('MyController',['MyService',function(MyService) {


   MyService.doSomeThing();

}]);

Comments

0

In addition to the answer provided by @mJunaidSalaat,

  1. You need to inject IONIC module to angular app module
  2. The remaining implementation will be as it is in Angular

As per below, you can:

angular.module('myApp', ['ionic']) 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.