2014-11-04 60 views

回答

1

您可以声明一个变量,它将保存this的引用,可用于后者。

app.service('myservice', function() { 
    //Declare a varible to hold reference 
    var _this = this; 
    this.messages = []; 
    this.myfunction1 = function() { 
     //Stuff 
     function myfunction2() { 
      //Use the reference variable 
      console.log(_this.messages) 
     } 
    } 
}); 
+0

完美,谢谢! – lukabers 2014-11-04 09:46:50