你能否在Angular 2中拥有独立指令?(Can you have a stand alone directive in Angular 2)
我正在玩Angular 2,我想做的是将一个独立的指令直接分配给HTML中的元素。 这可能吗?
指示:
import {Directive, ElementRef} from 'angular2/core'; @Directive({ selector: '[Slidernav]' }) export class Slidernav { constructor(private element: ElementRef) { console.log('Slider Run'); } }
我会将它分配给任何HTML元素,如下所示:
<div slidernav>Some content</div>
我问的原因是因为我不想使用Component在DOM中已经存在的HTML设置模板。
编辑
因此,基于响应,这是组件
组件滑块
import {Component, View, ElementRef} from 'angular2/core'; @Component({ selector: 'Slider', template: '<ng-content></ng-content>' }) export class Slider { constructor(private element: ElementRef) { console.log('Slider'); } }
的index.html
<Slider> <div>hello world</div> </Slider>
我希望Div能够在Slider中保留内容hello世界。 AFAIK,它应该如何工作基于我一直在阅读有关Transclusion的内容。 但控制台错误是:
Error: The component Slider has 1 <ng-content> elements, but only 0 slots were provided.
I'm playing around with Angular 2, What I'd like to do is to have a stand alone directive directly assigned to an element within the HTML. Is this possible?
Directive:
import {Directive, ElementRef} from 'angular2/core'; @Directive({ selector: '[Slidernav]' }) export class Slidernav { constructor(private element: ElementRef) { console.log('Slider Run'); } }
and I would assign it to any HTML element like so:
<div slidernav>Some content</div>
The reason why I'm asking is because I don't want to set the template with HTML that already exists in the DOM using a Component.
EDIT
So based on the responses, this is the component
Component Slider
import {Component, View, ElementRef} from 'angular2/core'; @Component({ selector: 'Slider', template: '<ng-content></ng-content>' }) export class Slider { constructor(private element: ElementRef) { console.log('Slider'); } }
index.html
<Slider> <div>hello world</div> </Slider>
I would be expecting the Div to remain within Slider with the content hello world. AFAIK that's how it should work based on what i've been reading about Transclusion. But the console error is:
Error: The component Slider has 1 <ng-content> elements, but only 0 slots were provided.
原文:https://stackoverflow.com/questions/35274885
最满意答案
boot2docker ssh "tce-load -w -i python.tcz"
也可以解决这个问题(你需要互联网;-))对于docker和ansible你需要“docker-py”
- 设置点,登录boot2docker
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install docker-py
还会添加到您的库存文件中:
dockerhost ansible_connection=ssh ansible_ssh_host=192.168.59.103 ansible_ssh_user=docker ansible_ssh_private_key_file=~/.ssh/id_boot2docker ansible_python_interpreter=/usr/local/bin/python
The solution was simple: Python isn't installed by default by Boot2Docker.
To install, run
$ boot2docker ssh "wget http://www.tinycorelinux.net/6.x/x86/tcz/python.tcz && tce-load -i python.tcz && rm -f python.tcz"
I created a script to do this automatically, see https://gist.github.com/bcattle/90e64fbe808b3409ec2f
相关问答
更多-
boot2docker怎么新增端口映射[2023-06-29]
在创建容器是加上-p 端口号 如:docker run -d -it -p 8080:8080 -p 8081:8081 --name xxxx ...... 就是将创建的容器的8080和8081 端口映射物理机的8080和8081端口,这里映射了2个端口 -
您将需要使用新的内存设置重新初始化boot2docker虚拟机: $ boot2docker delete $ boot2docker init -m 5555 ... lots of output ... $ boot2docker info { ... "Memory":5555 ...} 您现在可以boot2docker up并且映像将始终使用配置的内存量。 You will need to re-initialize the boot2docker VM with the new memory s ...
-
显然,boot2docker上的Google托管虚拟机存在一些问题。 我找到了一个适用于我的Ubuntu 14.04机器以及我的Windows 8.1机器的解决方案。 可以在此处找到分步指南: https : //gist.github.com/xuru/604da3c02ec96904d352 最关键的部分似乎是某个版本图像的下载: boot2docker download --iso-url=https://github.com/boot2docker/boot2docker/releases/down ...
-
是否有`boot2docker save`的替代/解决方法?(Is there an alternative/workaround for `boot2docker save`?)[2023-10-29]
解决方案/解决方法是使用用于运行VM的软件来保存VM的状态(在boot2docker是VirtualBox的情况下)。 重新启动后,您只需加载已保存的状态,事情就会像以前一样继续工作。 The solution/workaround is to save the state of the VM using the software used to run it (in the case of boot2docker that is VirtualBox). After a restart you can t ... -
ssh到boot2docker是使用该工具的常用方法:你ssh到boot2docker vm。 打开ssh会话后,您可以检查容器以列出每个容器的卷 。 docker inspect -f '{{ .Name }},{{ range $key, $value := .Volumes }}{{ $key }},{{ $value }}##~#{{ end }}'
注意:自.Mounts 1.8以来,检查卷现在使用.Mounts 。 请参阅“ 如何在docker容器中列出卷? ”。 ... -
请参阅“ 如何让Docker在公司防火墙后的Windows系统上运行? ” 你需要设置 在cmd会话中设置HTTP_PROXY , HTTPS_PROXY和NO_PROXY ,以便boot2docker download工作。 (导出) /var/lib/boot2docker/profile中的http_proxy , http_proxy和no_proxy ,以便执行/var/lib/boot2docker/profile docker search (例如)。 export http_proxy=ht ...
-
经过大量测试后,我决定使用NFS(网络文件系统)而不是rsync,这使我可以同步我的机器和Docker主机。 而且效果很好。 这种配置允许我管理它。 #sync local files to the docker host VM config.vm.synced_folder "../", "/vagrant", type: "nfs", mount_options: ["nolock", "vers=3", "udp"], id: "nfs-sync" 参考: https : //github.com/ ...
-
这意味着你的$PATH (在boot2docker会话中)以某种方式在 /bin 之前包含“ C:/Program Files (x86)/Git/bin/ ”。 检查docker run --rm -it ubuntu:latest时的$PATH docker run --rm -it ubuntu:latest 。 您设法在boot2docker ssh会话中运行映像,但boot2docker ssh docker ps似乎没有显示任何预期。 只有一个docker run --rm -it ubuntu ...
-
我怀疑你的容器没有启动,因为当机器(boot2docker VM)重新启动时,它仍然处于' Exited '状态。 用docker-machine ssh default "docker ps -a" 。 (在docker-machine start default ) 如果是这样,请在/mnt/sda1/var/lib/boot2docker/profile一个对脚本的调用,该脚本将: 测试容器是否退出 : docker inspect -f {{.State.Running}} $CONTAINER_I ...
-
boot2docker ssh "tce-load -w -i python.tcz"也可以解决这个问题(你需要互联网;-))对于docker和ansible你需要“docker-py” 设置点,登录boot2docker wget https://bootstrap.pypa.io/get-pip.py python get-pip.py pip install docker-py 还会添加到您的库存文件中: dockerhost ansible_connection=ssh ansible_ssh_ho ...