我如何访问角度模块内的函数?

时间:2017-03-19 02:42:43

标签: javascript angularjs

代码片段

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
}
]),

具体来说,我需要能够从chromes控制台调用withdraw函数。

2 个答案:

答案 0 :(得分:1)

您可以使用angular.injector

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

答案 1 :(得分: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;
}
]),