zoukankan      html  css  js  c++  java
  • [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";
                }
            }
        })
    }
  • 相关阅读:
    Python 类和对象
    Python zxing 库解析(条形码二维码识别)
    MFC&Halcon之实时视频监控
    MFC&Halcon之图片显示
    Halcon11与VS2010联合开发
    堆排序程序中的小于等于号问题
    cenos7 u disk install
    UML类图关系表示
    socket http1
    mfc http
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4792446.html
Copyright © 2011-2022 走看看