AngularDart: How to include subcomponents in a custom component template

落爺英雄遲暮 提交于 2019-12-12 14:51:25

问题


I've created a tabs component in AngularDart

@Component(
    visibility: Directive.CHILDREN_VISIBILITY,
    selector: "rtabs",
    templateUrl: "packages/myapp/components/rtabs.html",
    publishAs: "cmp",
    useShadowDom: false
)
class RTabsComponent {
    @NgAttr('label')
    String label;

    int selectedTabIndex = 0;

    RTabsComponent(){
    }

    var tabs = new List<RTabComponent>();

    add(RTabComponent tab) {
        tabs.add(tab);
    }
}

@Component(
    selector: "rtab",
    template: "<content></content >",
    publishAs: "cmp",
    useShadowDom: false
)
class RTabComponent {    
    @NgAttr('name')
    String name;

    RTabComponent(RTabsComponent tabs){
        tabs.add(this);
    }
}

and my use of the component is like

<rtabs label="System Settings">
    <rtab name="test">test 123</rtab>
    <rtab name="test 2">test abc</rtab>
    <rtab name="test 3"><input-custom ng-model="cmp.somevalue"></input-custom></rtab>
</rtabs>

I'm having a problem with rending the content of the rtab in the rtabs component template. I'm not sure what the correct syntax is for this.

If I do

<div ng-repeat="tab in cmp.tabs">
{{tab}}
</div>

It just prints out "Instance of 'RTabComponent'", which is understandable.

But how would I loop through the cmp.tabs in the template and render the actual content of the rtab?

I need the content to be work with the ng-model stuff and other components like the one in the 3rd tab.


回答1:


Answering my own question.

add a template to to rtab like

<div ng-class="{'tab-pane': true, active: cmp.active}">
    <content></content>
</div>

and in the rtabs.html

<div class="tab-content">
    <content></content>
</div>


来源:https://stackoverflow.com/questions/25733154/angulardart-how-to-include-subcomponents-in-a-custom-component-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!