【问题标题】:How to Add directive in gulp-browserify angular project如何在 gulp-browserify Angular 项目中添加指令
【发布时间】:2016-03-18 06:25:24
【问题描述】:

我正在使用此代码 - https://github.com/rahil471/scalable-angularjs-project-setup-gulp-browserify

它工作正常。但我面临的唯一问题是

该指令不起作用。

我做了什么 - 我在 'src' 的 'componenets' 中添加了 'directive' 文件夹,它完美地在 'public' 的组件中创建了 'directive' 的副本,但它正在显示应用程序未定义。 我在“directive”文件夹中创建了 custom.js 文件并将其包含在 index.html(最外层)中。

custom.js

app.directive('mydir', function() {
   return {
        restrict: 'E',
        template: '<h1>ANIL</h1>'
    };
});

在'src'的'component'中的about.html中添加

代码完美复制到'public'中'component'中的about.html。

【问题讨论】:

    标签: angularjs angularjs-directive gulp browserify


    【解决方案1】:

    对问题的解释很糟糕,但让我们试着弄清楚。所以你想创建额外的指令?如果是这种情况,那么您必须在 app.js (src/app/app.js) 中包含指令文件夹(和文件),如下所示:

    require('./components/directive/custom.js');
    

    Browserify 然后会知道将此文件包含到主包中,并且应用程序将识别您的指令。

    并且不要在索引文件中包含任何内容,browserify 和 gulp 将为您准备好一切。

    【讨论】:

      猜你喜欢
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-27
      • 2015-05-12
      • 2015-11-15
      相关资源
      最近更新 更多