码迷,mamicode.com
首页 > Web开发 > 详细

AngularJS+RequireJS最小单元

时间:2016-01-19 14:26:45      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

最简单配置,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...";
        });
});

展示结果:

技术分享

AngularJS+RequireJS最小单元

标签:

原文地址:http://www.cnblogs.com/LinSong/p/5141843.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!