Reputation: 289
Trying to load Angular library conditionally using Modernizr, if CDN fails want it to load the library from local machine but it is not working, so what could be the reason
Modernizr.load([
{
load: "//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular.min.js",
complete: function () {
if(!window.angular){
Modernizr.load("bower_components/angular/angular.min.js");
}
}
}]);
Thanks
Upvotes: 0
Views: 415
Reputation: 1292
Ok so like the error says, Modernizr doesn't know what angular is, which means your fallback doesn't work. Take a look at this code:
Modernizr.load([
{
load: '//ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.js',
complete: function () {
if (!window.jQuery) {
Modernizr.load('js/libs/jquery-1.6.4.min.js');
}
}
},
{
// This will wait for the fallback to load and
// execute if it needs to.
load: 'needs-jQuery.js'
}
]);
This code attempts to load jQuery from the Google CDN first. Once the script is downloaded (or if it fails) the function associated with complete will be called. The function checks to make sure that the jQuery object is available and if it’s not Modernizr is used to load a local jQuery script. After all of that occurs a script named needs-jQuery.js will be loaded. http://weblogs.asp.net/dwahlin/detecting-html5-css3-features-using-modernizr
Edit
so change this
load: "//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular.min.js",
to this
load: https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.4/angular.min.js,
Upvotes: 1