你的位置:首页 > Java教程

[Java教程]AngularJS+RequireJS最小单元


最简单配置,RequireJS结合AngularJS:

index.html

 1 <!DOCTYPE html> 2 <html> 3 <head> 4   <meta charset="UTF-8"> 5   <script type="text/javascript" src="require.js" data-main="main.js"></script> 6 </head> 7 <body> 8   <div ng-controller="demoController"> 9     <label><input type="text" ng-model="results"/></label>10     <br/>11     <span ng-bind="results"></span>12   </div>13 </body>14 </html>

main.js

require.config({  paths:{    "angular":"angular"  },  shim:{   "angular":{     exports: "angular"   }  }});require(["angular","app"],function(angular,app){  angular.bootstrap(document,['demoApp']);});

app.js

define(["angular"], function(angular){  var app=angular.module("demoApp",[])    .controller("demoController", function($scope){      $scope.results="To be defined...";    });});

展示结果: