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

[AngularJS + Webpack] require directives

时间:2015-04-13 06:51:49      阅读:223      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!