如何在 gulp-browserify angular 项目中添加指令
How to Add directive in gulp-browserify angular project
我正在使用此代码 - https://github.com/rahil471/scalable-angularjs-project-setup-gulp-browserify
它工作正常。但我面临的唯一问题是
该指令无效。
我做了什么 - 我在 'src' 中的 'componenets' 中添加了 'directive' 文件夹,它正在创建 [=32] 的副本=] 在 'public' 的组件中完美,但它显示未定义的应用程序。
我在 'directive' 文件夹中创建了 custom.js 文件,并将其包含在 index.html(最外层)中。
custom.js
app.directive('mydir', function() {
return {
restrict: 'E',
template: '<h1>ANIL</h1>'
};
});
添加到 about.html 到 'component' 到 'src'
代码完美复制到about.html in 'component' in 'public'
对问题的解释很糟糕,但让我们试着找出答案。所以你想创建额外的指令?如果是这种情况,那么您必须在 app.js (src/app/app.js) 中包含指令文件夹(和文件),如下所示:
require('./components/directive/custom.js');
然后 Browserify 将知道将此文件包含到主包中,应用程序将识别您的指令。
并且不要在索引文件中包含任何内容,browserify 和 gulp 将为您准备好一切。
我正在使用此代码 - https://github.com/rahil471/scalable-angularjs-project-setup-gulp-browserify
它工作正常。但我面临的唯一问题是
该指令无效。
我做了什么 - 我在 'src' 中的 'componenets' 中添加了 'directive' 文件夹,它正在创建 [=32] 的副本=] 在 'public' 的组件中完美,但它显示未定义的应用程序。 我在 'directive' 文件夹中创建了 custom.js 文件,并将其包含在 index.html(最外层)中。
custom.js
app.directive('mydir', function() {
return {
restrict: 'E',
template: '<h1>ANIL</h1>'
};
});
添加到 about.html 到 'component' 到 'src'
代码完美复制到about.html in 'component' in 'public'
对问题的解释很糟糕,但让我们试着找出答案。所以你想创建额外的指令?如果是这种情况,那么您必须在 app.js (src/app/app.js) 中包含指令文件夹(和文件),如下所示:
require('./components/directive/custom.js');
然后 Browserify 将知道将此文件包含到主包中,应用程序将识别您的指令。
并且不要在索引文件中包含任何内容,browserify 和 gulp 将为您准备好一切。