Angularjs share functions inside service

2019-02-28 06:32发布

问题:

I am working with an angular app, where service are as declared as follows:

App.service("myService", function(){
  this.calculation1 = function(){
    var util = function(){
    }
    //doing somthing
  }
  this.calculation2 = function(){

    // how can I call util function here?
  }
}

I want to use util function inside calculation2 method.

How can I do that?

Thanks in advance.

回答1:

Just declare it outside the calculation1 function:

App.service("myService", function(){
  var util = function(){
  }
  this.calculation1 = function(){
    //doing something
  }
  this.calculation2 = function(){

  }
}