[AngularJS + Webpack] Requiring Templates

With Angular, most of the time you‘re specifying a templateUrl for your directives and states/routes. This means you need to make sure that you‘re loading in these templates into the $templateCache for your tests and production. Oh, and don‘t forget to update all your URLs whenever you move the files around! When you add in Webpack and the html-loader, you don‘t need to do this anymore. Simply require the html file and your work is done!

Install:

npm install -D html-loader

webpack.config.js:

module.exports = {
    entry: {
        app: [‘./app/index.js‘]
    },
    output: {
        path: ‘./build‘,
        filename: ‘bundle.js‘
    },
    module: {
        loaders: [
            {test: /\.js$/, loader: ‘babel-loader‘, exclude: /node_modules/},
            {test: /\.html$/, loader: ‘html-loader‘, exclude: /node_modules/}
        ]
    }
};

hello.js:

export default (ngModule) => {
    ngModule.directive(‘hello‘,  () => {
        return {
            restrict: ‘E‘,
            scope: {},
            template: require(‘./hello.html‘),
            controllerAs: ‘vm‘,
            controller: function() {
                var vm = this;
                vm.greeting = "Hello";
            }
        }
    })
}
时间: 2024-12-10 19:28:51

[AngularJS + Webpack] Requiring Templates的相关文章

[AngularJS + Webpack] Requiring CSS & Preprocessors

Making your CSS modular is a difficult thing to do, but using Webpack makes this so much easier. By adding a single line to your Webpack config, you can require you CSS, Stylus, Less, etc. files right from your directives and keep everything together

[AngularJS + Webpack] require directives

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: '

[AngularJS + Webpack] Using Webpack for angularjs

1. Install webpack & angular: npm install webpack angular 2. Create webpack.config.js file: module.exports = { context: __dirname + '/app', entry: './app.js', output: { path: __dirname + '/build', filename: 'bundle.js' } } The context is: app folder

虽然今天angular5发布了,但我还是吧这篇angularjs(1)+webpack的文章发出来吧哈哈哈

本文为原创,转载请注明出处: cnzt       文章:cnzt-p http://www.cnblogs.com/zt-blog/p/7779384.html 写在前面: 因为最近总结自己之前做过的东西,所以顺便总结了这一篇,要发布文章时,刚好看到手机推送消息"angular5发布啦"啊哈哈哈哈哈哈.我不管我还是要把关于angular1的这篇文章放上来因为还涉及到webpack呢啊哈哈哈哈哈哈哈哈-- Angularjs+webpack实现模拟微信菜单编辑功能 1       环境

AngularJS开发指南11:AngularJS的model,controller,view详解

model model这个词在AngularJS中,既可以表示一个(比如,一个叫做phones的model,它的值是一个包含多个phone的数组)对象,也可以表示应用中的整个数据模型,这取决于我们所讨论的AngularJS文档中的上下文. 在AngularJS中,一个模型就是AngularJS作用域对象中的任何一个可取的属性.属性的名字就是模型的标示符.它的值可以是任意的Javascript对象(包括数组和原始对象). 将Javascript对象变成模型的唯一要求是这个对象必须是AngularJ

webpack打包懒加载

lazyload https://webpack.js.org/guides/lazy-loading/ 懒加载 -- 按需加载. Lazy, or "on demand", loading is a great way to optimize your site or application. This practice essentially involves splitting your code at logical breakpoints, and then loading

大型分布式电商项目---品优购

概述 这是一个综合性的B2B2C平台,类似京东商城.天猫商城.网站采用商家入驻的模式.该项目采用Spring+SpirngMVC+Mybatis框架搭建的maven工程,并采用分布式架构按功能将系统分为不同的子系统,将不同的子系统部署到不同的节点服务器独立运行.在各个系统之间采用dubbox+zookeeper进行通信,实现了基于SOA面向服务的架构,使得服务层与表现层分离,此项目为本人学习项目,为传智播客,最后一个商城实战项目,前前后后花了2个月左右,后面几天的内容暂时没做,因为电脑吃不消,完

AngularJs学习笔记--Understanding Angular Templates

原版地址:http://docs.angularjs.org/guide/dev_guide.mvc.understanding_model angular template是一个声明规范,与model.controller的信息一起,渲染成用户在浏览器中所看到的视图.它是静态的DOM,包括HTML.CSS.angular特别的元素和angular指定的元素属性.angular元素和属性指示angular去扩展行为以及将template DOM转换为动态视图的DOM. 下面是我们可以在templ

Part 35 AngularJS caseInsensitiveMatch and Inline Templates

In this video we will discuss 2 simple but useful features in Angular caseInsensitiveMatch Inline Templates Let us understand these 2 features with examples. caseInsensitiveMatch : The routes that are configured using config function are case sensiti