【发布时间】:2016-10-30 02:37:36
【问题描述】:
我已经按如下方式创建了 ContentPage 组件:
@Component({ selector: 'content-page',
template: '<ng-content></ng-content>' })
export class ContentPage {
}
然后在模块中引导它:
@NgModule({
imports: [ BrowserModule ],
declarations: [ ContentPage ],
bootstrap: [ ContentPage ]
})
export class AppModule { }
页面模板为:
<!DOCTYPE html>
<html>
... angular2 quickstart head ...
<body>
<div class="container" style="padding-top: 20px">
<content-page>
<div style="float: right; width: 150px">
<content-button-edit></content-button-edit>
</div>
<div data-page-id="{{page-id}}">
Some content here
</div>
</content-page>
</div>
</body>
</html>
当页面加载时,“这里有一些内容”会出现片刻然后消失。我想应该在 ContentPage 的模板中插入它而不是 ng-content,因为我在其中有 ng-content 指令。当我更改页面模板时,它会更改输出,因此肯定会应用它。
有没有办法保留组件的标记内容?
更新:
我想要实现的是在服务器上生成带有内容的 HTML 页面,然后添加动态功能。
由于内容按钮编辑实际上应该隐藏“此处的某些内容”并显示编辑页面控件,因此我正在考虑使用同时包含 和 的容器组件。
因此 template 或 templateUrl 不是选项。
【问题讨论】:
-
为什么不在定义
content-page选择器的 html 中添加标记? -
内容页面的内容应该在服务器上创建。所以我认为 template/templateUrl 不是选项。
-
@yurzui 嗯...这很可悲。
标签: angular