简体   繁体   English

如何知道浏览器的内置对象已准备就绪?

[英]How to know the browser build-in object in ready in angular?

The background: The wechat JS API is on the foundation of wechat build-in browser object WeixinJSBridge. 背景:微信JS API在微信内置浏览器对象WeixinJSBridge的基础上。 The WeixinJSBridge is not ready immediately when open the WebView,client side need initialize this object, when this object is ready,client side will fire "WeixinJSBridgeReady", so before invoke WeixinJSBridge API, we need check WeixinJSBridge is ready or not: 打开WebView时,WeixinJSBridge尚未立即准备就绪,客户端需要初始化该对象,当该对象准备就绪时,客户端将触发“ WeixinJSBridgeReady”,因此在调用WeixinJSBridge API之前,我们需要检查WeixinJSBridge是否准备就绪:

if (typeof WeixinJSBridge == "object" && typeof WeixinJSBridge.invoke == "function") {
    WeixinJSBridge.invoke'API()....
} else {
    if (document.addEventListener) {
        document.addEventListener("WeixinJSBridgeReady", callback, false);
    } else if (document.attachEvent) {
        document.attachEvent("WeixinJSBridgeReady", callback);
        document.attachEvent("onWeixinJSBridgeReady", callback);
    }
}

here is the question: how can I do this check in context of angular, i want put this stuff in one controllers. 这里的问题是:我该如何在角度环境中进行检查,我想把这些东西放在一个控制器中。

Use .run: http://docs.angularjs.org/api/angular.Module 使用.run: http//docs.angularjs.org/api/angular.Module

var app = angular.module('myApp',[]);
app.run(/*standard function and scope*/);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM