- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我有一个关于 angular2 的问题。我正在创建一些组件并希望拥有这样的东西:
这是我的 DogComponent 类:
@Component({
selector: "dog",
template: "dog.template.html"
})
class DogComponent
{
@Input() image: string;
}
以及 dog.template.html 中的模板:
<div>
<!-- Content of <top> should go here -->
<img class="after" src="dogs/{{image}}" />
<!-- Content of <bottom> should go here -->
</div>
当我使用 DogComponent 时,它应该使用传递的 src 创建 img-tag,还可以查看图像前后的其他 HTML 部分。
所以最后,如果我写这段代码:
<dog image="garry.png">
<top>
<h1>This is Garry!</h1>
</top>
<bottom>
<span>He is my favorite dog!</span>
</bottom>
</dog>
它应该被渲染成这样:
<dog>
<div>
<h1>This is Garry!</h1>
<img src="dog.png" />
<span>He is my favorite dog!</span>
</div>
</dog>
有人知道我的问题的答案吗?
那就太好了!
编辑:
感谢您的建议,所以现在我更新了代码片段并添加了 DogListComponent
。如果我在我的应用程序中的某处使用标记 dog-list
,则应该查看最后一个片段(浏览器结果)。希望现在更清楚了。
狗.component.ts
@Component({
selector: "dog",
templateUrl: "dog.template.html"
})
class DogComponent
{
@Input() image: string;
}
狗.template.html
<div>
<!-- Content of <top> should go here -->
<img class="after" src="dogs/{{image}}" />
<!-- Content of <bottom> should go here -->
</div>
dog_list.component.ts
@Component({
selector: "dog-list",
templateUrl: "dog-list.template.html"
})
class DogListComponent
{
}
狗列表.template.html
<dog image="garry.png">
<top>
<h1>This is Garry!</h1>
</top>
<bottom>
<span>He is my favorite dog!</span>
</bottom>
</dog>
<dog image="linda.png">
<top>
<h1>My little Linda :)</h1>
</top>
<bottom>
<span>She is my cutest dog!</span>
</bottom>
</dog>
<dog image="rex.png">
<top>
<h1>And here is Rex!</h1>
</top>
<bottom>
<span>DANGEROUS!</span>
</bottom>
</dog>
浏览器结果:
<dog-list>
<dog image="garry.png">
<top>
<h1>This is Garry!</h1>
</top>
<bottom>
<span>He is my favorite dog!</span>
</bottom>
</dog>
<dog image="linda.png">
<top>
<h1>My little Linda :)</h1>
</top>
<bottom>
<span>She is my cutest dog!</span>
</bottom>
</dog>
<dog image="rex.png">
<top>
<h1>And here is Rex!</h1>
</top>
<bottom>
<span>DANGEROUS!</span>
</bottom>
</dog>
<dog-list>
最佳答案
所以我找到了我的解决方案!我需要使用 <ng-content>
.
dog.template.html 看起来像这样:
<div>
<ng-content select="top"></ng-content>
<img class="after" src="dogs/{{image}}" />
<ng-content select="bottom"></ng-content>
</div>
然后它将插入指定的<top>-tags
和 <bottom>-tags
在我的分区中。
关于html - Angular 2 : How to show inner HTML of component-tags inside of component?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41767834/
class Outer { class Inner { } } public class Demo { public static void main(
我在我的 PC 上使用 bitnami WAMP 创建了一个 mysql 服务器,并使用流畅的 SQL 创建了两个表 table_a 和 table_b: CREATE TABLE `table_a`
select sld.linkid,sld.accept,scd.catid,scd.catname,scd.caturl,scd1.parentcatid from sound_li
为什么在实例化通用外部类(连同内部类)时使用菱形运算符会在代码段 2 中产生错误,而代码段 1 却完全没问题? 我知道稀有类型是被禁止的,但我的情况不是稀有类型——在稀有类型中,外部和内部都是通用的,
这不是那么重要(请注意),但它是一个语法特殊性,它是关于可移植性的,我没有找到引用可靠资源或规范的问题(或答案),所以我很好奇: 省略 INNER 是否安全关键字,如果我明确想要 INNER JOIN
同一查询的这两个版本之间的性能有什么区别吗? --Version 1 SELECT p.Name, s.OrderQty FROM Product p INNER JOIN SalesOrderDet
阅读 Doctrine 2 文档时 at this page我可以看到他们有两种方法来指定内部连接的条件: // Example - $qb->expr()->innerJoin('u.Group',
我想知道我怎么能直接从外部类型到达内部类,就好像它是一个静态成员一样: public class Hello { public class UnderHello { v
我有一个这样的界面: public interface SuperInterface { public interface SubInterface { public void
假设有两个表: students (student_id INT, class_id INT); instructors (instructor_id INT, class_id INT); 这两者之
有表 A 和表 B。我想将这些表连接到两列,但仅限于表 A 的选定行。 查询场景: SELECT B.* FROM B INNER JOIN (SELECT * FROM A WHERE A.COLU
今天我了解了SQL Server中的一个东西,叫做INNER LOOP JOIN . 这是什么意思? (谷歌没有提供帮助……或者我应该说……有关它的博客文章有点……技术性,让我大吃一惊)。 此外,在哪
我开始学习 SQL。而且我发现我们经常可以在 JOIN 或内部选择语句的帮助下获得相同的结果。 问题 1(广泛):JOIN 在哪里比内部选择更快,反之亦然? 问题 2(窄):您能解释一下是什么导致了以
我真的很努力地完成这项任务,因此非常感谢任何帮助或指导。 表格: module_uploads +--------------------------+
仅当连接表中存在记录时,我才尝试根据连接表中的条件从用户表中选择一行。如果记录不存在,我想返回该行。我只想在存在 INNER JOIN 记录且 contact_blocked != 1 时不返回该行。
我有一个包含字符的数据库。由于角色的名称不仅在名称与角色分开时才使用。由于有 Male 和 Female 字符,我将它们保存在不同的表中: tbl_player, tbl_maleName, tbl_
[决定如何表述问题并不容易...] 这是一个 example jsfiddle . 紫色的 div ('#inner') 高 1000 像素。 如何制作红色 div ('#out') 的滚动条 - 控
我正在为 wordpress 中的帖子开发一个过滤器,它使用来自 postmeta 的数据:我的日期过滤器正在运行并给我这个查询: 工作查询结果: SELECT SQL_CALC_FOUND_ROWS
我有使用引导类并动态添加 带有引导类和 clearfix 的元素 var li = $("").addClass("list-group-item clearfix"); var div = $(
我已经为 Test_flow 创建了简单的测试套件,但是当我尝试运行该流程时出现错误。 java.lang.RuntimeException: org.mule.api.config.Configur
我是一名优秀的程序员,十分优秀!