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 ~