简体   繁体   English

如何将后备js与angular模块一起使用?

[英]How can I use fallback js with angular modules?

I'm using fallback to load a local file if the cdn is unavailable; 如果CDN不可用,我正在使用后备加载方式加载本地文件;

The readme states: "The key must be the libraries window variable" - for example jQuery (or $ I guess) for jquery. 自述文件指出:“键必须是库窗口变量”,例如jquery的jQuery(或$我猜)。

fallback.load({
    // [...]
    jQuery: [
        '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.FAIL_ON_PURPOSE.min.js',
        '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js',
        '//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js'
    ],

    'jQuery.ui': [
        '//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
        '//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js',
        '//js/loader.js?i=vendor/jquery-ui.min.js'
    ]
}, //[...] shim, callback etc 
});

However, when loading angularjs modules or jquery plugin, I do not have a window library to use as a test. 但是,在加载angularjs模块或jquery插件时,我没有用作测试的窗口库。

Is there any way to use the library? 有没有使用图书馆的方法?

Yes, there is: - just use an expression that would return undefined if the library is not loaded: 是的,有:-仅使用一个表达式,如果未加载库,该表达式将返回未定义:

This is the github issue and this is the plunker : 这是github问题 ,这是小问题

fallback.load({
    //[...]
    'angular.module("ngRoute")': [
            '//ajax.googleapis.com/ajax/libs/angularjs/1.2.3/angular-route.min.js'
        ],
    //[...]
});

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

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