Home > Web Front-end > JS Tutorial > require' modular jquery and angular issues

require' modular jquery and angular issues

巴扎黑
Release: 2017-06-23 10:54:15
Original
983 people have browsed it

require Modular development issues, normally the module you write is exports to export a module

//Differences and problems with modular introduction of jquery

require Introduction of jquery swiper.... Plug-in and When using the library, you need

require.config({
​baseUrl:"js/libs", ​ //The location of the folder directory relative to html
​paths:{
​ ​ ​ 'jquery':" jquery-1.9.1" //The file name of the plug-in or library
  'swiper':"File name/swiper" //This can also be changed when each plug-in and library are not in the same folder
 }
})

define(['angular','swiper'],function($){ //Write the plugin and library variables you saved above in square brackets
//jquer/ Just write how swiper is written here

//If you want to return a native method, you need
var fn=function(){};

//We need to use a json object to write this The method returns and does not export the module to normal exports
return {fn:fn}
})

//Use html: require(['file name'],function(mod){
MOD.FN (); // How to use Return
})

// Modularization introduces Angular development problem Angular does not use AMD module specifications

Require.config ( {
baseUrl:"js/libs", //The location of the folder directory relative to html
paths:{
       'angular':"angular.min" //angular file name
 },
 shim:{
  'angular':{exports:'angular'} //Need to export a global variable named angular
  }
})
define('app',[ 'angular'],function(){ //The previous app is the file name and turns the current file into an AMD module
//Write angular normally
var app=angular.module('mk',[])
return app; //This returns the angular definition module

})

The above is the detailed content of require' modular jquery and angular issues. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template