AngularJS - 从同一服务调用服务中的函数

AngularJS - Call function in service from the same service

HTML

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

Ctrl

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

服务

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();
    }
    }
);

我在这里调用服务getVLC,但它说getVLC 未定义。如何从同一服务调用一项服务?

P.S。两个函数在同一个服务中

如果这两个函数在同一个文件中,您必须像这样保存对 this 的引用:

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

更新

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();
    }
  }
  );