使用结构指令,我如何获得指令所在的(本机)元素?使用普通指令,ElementRef具有指向它的nativeElement - 例如:
<input type="text" example>
@Directive({
selector: '[example]'
})
export class ExampleDirective {
constructor( private el: ElementRef) {}
ngAfterViewInit() {
console.log(this.el.nativeElement); // the input
}
}
Run Code Online (Sandbox Code Playgroud)
但是使用结构指令,它指向模板注释 - 例如.
<input type="text" *example>
@Directive({
selector: '[example]'
})
export class ExampleDirective {
constructor(
private el: ElementRef,
private view: ViewContainerRef,
private template: TemplateRef<any>
) {}
ngAfterViewInit() {
this.view.createEmbeddedView(this.template);
console.log(this.el.nativeElement); // template bindings comment
// how to find the input itself?
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用ViewContainerRef,TemplateRef,@ ContentChild,@ ViewChild的各种组合 - 只是似乎无法找到输入元素本身......
我有一个可怕的时间使用yeoman/grunt和usemin - 当我有子文件夹时,试图让输出文件同时在html中编写正确的路径.
我的基本设置是有顶级页面(例如index.html)以及子文件夹中的语言特定页面(en,de,fr等) - 每个页面都有常见的js文件(如jquery)但也有语言特定的js文件(css相同,但保持简单......)
– Gruntfile.js
– app
|– index.html
|– js
jquery.js
|– en
english.js
|– de
german.js
|– css
|– en
|– index.html
|– de
|– index.html
– dist
Run Code Online (Sandbox Code Playgroud)
所以基本上 - 有顶级index.html有jquery等 - 所以那里的脚本标签可能看起来像
<script src="js/jquery.js"></script>
Run Code Online (Sandbox Code Playgroud)
或与转速
<script src="js/123.jquery.js"></script>
Run Code Online (Sandbox Code Playgroud)
但是在en/index.html中,脚本标记应该看起来像(对于常见的 - 比如jquery)
<script src="../js/jquery.js"></script>
Run Code Online (Sandbox Code Playgroud)
或与转速.
<script src="../js/123.jquery.js"></script>
Run Code Online (Sandbox Code Playgroud)
这是../这就是麻烦.
我可以创建js文件但不是rev'd,或者rev'd但是空,或者构建和rev'd但是在错误的位置(最常见的是在app和dist文件夹之外/之上!)
在en/index.html中 - 我无法弄清楚构建:js应该是什么样子,例如.
<!-- build:js js/jquery.js -->
<script src="../js/jquery.js"></script>
<!-- endbuild -->
<!-- build:js js/en/english/jquery.js -->
<script src="../js/en/english.js"></script>
<!-- endbuild -->
Run Code Online (Sandbox Code Playgroud)
我已经尝试了我能想到的每一个组合 - 似乎归结为如果我在build:js路径中编写../,那么实际文件从app文件夹放置1级,但写入路径正确的HTML.如果我离开../ out,它将文件放在正确的位置,但是html中没有../(它显然需要) - 所以我怎么说我想要输出文件到引用一级(从en …
我正在尝试制作一个脚本,该脚本仅在 master 是当前签出的分支时才运行...
我设法通过以下方式获取了分支名称:
git rev-parse --symbolic-full-name --abbrev-ref HEAD
Run Code Online (Sandbox Code Playgroud)
但是把它放在一个脚本中,检查它的价值并根据它做一件事或其他事情并不顺利
"foo": "set branch=git rev-parse --symbolic-full-name --abbrev-ref HEAD | if [branch==master]; then echo \"yes\"; else echo \"no\"; fi;"
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
试图让中间件在 Fastify 中工作 - 我似乎无权访问查询或参数。文档说:
Fastify 支持开箱即用的 Express/Restify/Connect 中间件,这意味着您只需插入旧代码即可运行!(顺便说一下,更快)
但举个简单的例子:
fastify.use(function(req, res, next) {
console.log('req.query', req.query); // undefined
console.log('req.params', req.params); // undefined
next();
});
Run Code Online (Sandbox Code Playgroud)
如果我添加/限制网址,则相同:
fastify.use('/foo', function(req, res, next) {
Run Code Online (Sandbox Code Playgroud)
我确定我遗漏了一些东西,但文档确实声称它“正常工作”-如果您无法访问 qs,我看不出怎么办?
[我想我可以重写以使用钩子,但我真的很感兴趣我打算如何使用中间件来做到这一点]
谢谢
angular ×1
fastify ×1
git ×1
grunt-usemin ×1
gruntjs ×1
javascript ×1
middleware ×1
node.js ×1
npm ×1
npm-scripts ×1
path ×1
subdirectory ×1
yeoman ×1