Use requirejs to manage angularJS dependency examples

Source: Internet
Author: User

Use requirejs to manage angularJS dependency examples

There is no explanation about what requirejs is here. It only uses pure code to make you feel the powerful dependency management of requirejs.

1. First download require. js, and then reference other JavaScript files in main. js.

// Configure the dependency require. config ({paths: {"angular": "angular"}, shim: {"angular": {"deps": [], "exports ": "angular" }}); // defines the module define (['angular ', 'controller'], function (angular) {angular. module ('hellomodel', ['helloctrls']); return {angularModules: ['hellomodel'] };});


 

2. Define controller Module controller. js in angular

 

define([ 'angular' ], function(angular) {    var componentCtrls = angular.module('HelloCtrls', []);     componentCtrls.controller('helloCtrl', [ '$scope', function($scope) {        $scope.greet = "hello world";      } ]);    return componentCtrls;});


 

Create an index.html file in the Third Region

 

  <Script src = "js/require. js" data-main = "js/main" defer async = "true"> </script >{{ greet }} 


 

Iv. File Organization Structure

 

The simplest demo can be used to give you a compliment! It may be modified later. You are also welcome to raise your comments O ~


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.