首页 > Web开发 > 详细

[AngularJS + Webpack] require directives

时间:2015-04-13 06:51:19      阅读:391      评论:0      收藏:0      [点我收藏+]

技术分享

direictives/index.js:

module.exports = function(ngModule) {
    //register all the directives here
    require(‘./hello‘)(ngModule);
};

 

directives/hello.js

module.exports = function(ngModule) {
  ngModule.directive(‘webHello‘, function() {
      return {
          restrict: ‘E‘,
          scope: {},
          templateUrl: ‘directives/hello.html‘,
          controller: function() {
              var vm = this;

              vm.greeting = "Hello Webpack!";
          },
          controllerAs: ‘vm‘
      }
  })
};

 

directives/hello.html:

<h1>
    {{vm.greeting}}
</h1>

 

app/index.js:

var angular = require(‘angular‘);
var ngModule = angular.module(‘app‘, []);

//require directives folder, then it will find index.js file require(
‘./directives‘)(ngModule); console.log(ngModule);

 

app/index.html:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Webpack + AngularJS</title>
</head>
<body ng-app="app">
    <web-hello></web-hello>
</body>
<script src="../build/bundle.js"></script>
</html>

 

[AngularJS + Webpack] require directives

原文:http://www.cnblogs.com/Answer1215/p/4421186.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!