【发布时间】:2017-06-07 16:58:55
【问题描述】:
我正在构建一个包含标题和内容的容器。我可以通过单击标题来切换容器并显示我的内容。在我的标题中还有一些信息,在每个切换状态中都可见。它看起来像这样:
关闭(只是标题):
打开(标题和内容):
我使用角度组件来构建这个:
myContainer.ts:
/** @ngInject */
export class MyContainer extends Controller {
static componentName = 'myContainer';
static templateUrl = 'app/comp/components/myContainer/myContainer.html';
static componentOptions: ng.IComponentOptions = {
transclude: true,
bindings: {
headerTitle: '@'
}
};
headerTitle: string;
isShownBlock: boolean = false;
constructor(
) {
super();
}
}
myContainer.html:
<div class="containerHeader" ng-click="ctrl.isShownBlock = !ctrl.isShownBlock">
<my-icon icon="arrow-filled"></my-icon>
<div class="containerTitle">{{ctrl.headerTitle}}</div>
</div>
<div class="containerContent" ng-if="ctrl.isShownBlock">
<div class="containerInnerContent" ng-transclude>
<!--TRANSCLUDED_CONTENT-->
</div>
</div>
在我的代码中使用 myContainer:
<my-container header-title="my container">
transcluded things
</my-container>
如您所见,我使用binding 设置我的容器标题并使用ng-transclude 嵌入我的内容。现在我想用ng-transclude 设置我的容器标题。我的问题是,我不知道如何区分标题和内容的嵌入内容?我尝试为标题构建一个自己的组件并将其放在<my-container></my-container> 的东西中,并使用ng-transclude,但我没有得到最终的解决方案。我希望它足够清楚,有什么想法吗?
【问题讨论】:
标签: html angularjs components angularjs-ng-transclude