1

HTML

<input type="button" id="PlayOrPause" style="width:60px" value="Play" onClick='doPlayOrPause();'>

Ctrl

$scope.doPlayOrPause = function(){
 cameraModuleService.doPlayOrPause();
}

Service

cameraModuleService.service('cameraModuleService', function ($http, $timeout, ENV, $log, $rootScope, $cookieStore, $compile) {  

    this.getVLC = function(){
    if( window.document[name] ){
        return window.document[name];
    }
    if( navigator.appName.indexOf("Microsoft Internet") == -1 ){
        if( document.embeds && document.embeds[name] )
            return document.embeds[name];
    }else{
        return document.getElementById(name);
    }
    }

    this.doPlayOrPause = function(){
    var vlc = getVLC("vlc");
    if( vlc )
    {
        if( vlc.playlist.isPlaying )
            vlc.playlist.togglePause();
        else
            vlc.playlist.play();
    }
    }
);

Here I am calling service getVLC, but it says getVLC is not defined. How do I call one service from the same service ?

P.S. Both functions are in the same service

Slimshadddyyy
  • 4,085
  • 5
  • 59
  • 121

1 Answers1

2

If these two functions are in the same file, you have to save the reference on this like this:

var self = this;
this.doPlayOrPause = function(){
    var vlc = self.getVLC("vlc");
    ...
}

UPDATE

cameraModuleService.service('cameraModuleService', function ($http, $timeout, ENV, $log, $rootScope, $cookieStore, $compile, $window) {

  this.getVLC = function () {
    if ($window.document[name]) {
      return $window.document[name];
    }
    if (navigator.appName.indexOf("Microsoft Internet") == -1) {
      if (document.embeds && document.embeds[name])
        return document.embeds[name];
    } else {
      return document.getElementById(name);
    }
  }

  var self = this;
  this.doPlayOrPause = function () {
    var vlc = self.getVLC("vlc");
    if (vlc) {
      if (vlc.playlist.isPlaying)
        vlc.playlist.togglePause();
      else
        vlc.playlist.play();
    }
  }
  );