2017-03-19 75 views
0

的代碼如何訪問角度模塊內的功能?

angular.module("app.wallet", ["app.wallet.directive", "app.wallet.service"]), 
angular.module("app.wallet.service", []).factory("$wallet", ["$rootScope", "$$http", "$e", "$toast", "errorMap", "$popup", "$google", function(t, e, n, a, r, o, i) { 
    var s = {}; 
    return s.withdraw = function(t) { 
     var n = e.link({ 
      method: "POST", 
      url: "/btc/withdraw", 
      data: { 
       amount: t.amount, 
       address: t.btcAddress 
      }, 
      success: Do stuff 
      failure: Do other stuff 
     }); 
     n.req() 
    } 
    , 
    s 
} 
]), 

片段具體來說,我需要能夠調用由鉻合金控制檯退出功能。

回答

1

您可以使用angular.injector

angular.injector(['app.wallet']).get('$wallet').withdraw(); 
0

例如,您可以通過編寫window.saved = s來附加任何東西到窗口。

從調試控制檯

然後,如果代碼被執行之前,你將有saved可供選擇:

angular.module("app.wallet", ["app.wallet.directive", "app.wallet.service"]), 
angular.module("app.wallet.service", []).factory("$wallet", ["$rootScope", "$$http", "$e", "$toast", "errorMap", "$popup", "$google", function(t, e, n, a, r, o, i) { 
    var s = {}; 
    s.withdraw = function(t) { 
     var n = e.link({ 
      method: "POST", 
      url: "/btc/withdraw", 
      data: { 
       amount: t.amount, 
       address: t.btcAddress 
      }, 
      success: Do stuff 
      failure: Do other stuff 
     }); 
     n.req() 
    } 
    window.saved = s; 
    console.log('you can now acces withdraw by typing saved.withdraw in your console'); 
    return s; 
} 
]),