Integration of Require. js and Angular. js

Source: Internet
Author: User

Integration of Require. js and Angular. js
Require. js

For details, see:
First knowledge of Require. js
Decrypt Require. js

Angular. js

For details, see:
Angular. js: Love and hate

Integrate Require. js and Angular. js configurations

Configure angular. js in Requirejs.
Require-main.js

// Configure requirejs. config ({... paths: {'jquery ': 'libs/jquery-2.1.3/jquery. min', 'angular ': 'libs/angular-1.3.15/angular. min'}, shim: {'angular ': {deps: ['jquery'], exports: 'angular '}},...});
Create

Create an Angularjs application module.
Angular-app.js

// Create define (['angular '], function (angular) {return angular. module ('angularapp', []);});
Load and start

Load and start Angularjs through Requirejs
Require-bootstrap.js

GlobalConfig. requireScripts. unshift ('angular ', 'angularapp'); // load requirejs (GlobalConfig. requireScripts, function (angular) {// start $ (document ). ready (function () {angular. bootstrap (document, ['angularapp']) ;});
Page reference
<script src=/libs/require/require.js></script><script src=/require-main.js></script><script src=/require-bootstrap.js></script>
File references Angular. js

Introduce angularjs module through Requirejs dependency Injection

Define (['angularapp' // introduce angularjs], function (angularApp) {angularApp. factory ('loginservice', function () {var loginService ={}; loginService. login = function (data) {window. location. href = '/welcome';}; return loginService ;});});
Dynamically load js files through Requirejs

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.