相关疑难解决方法(0)

从angular 4中的html中删除主机组件标记

我有一个表,我想在其中显示一个表行,这是一个组件.而且我还想将数据传递给该组件:

<table>
    <th>
        <td>col 1</td>
        <td>col 2</td>
        <td>col 3</td>
    </th>
    <tr>
        <my-component [data1]="data1" [data2]="data2"></my-component>
    </tr>
    <tr *ngFor="let item of list">
        {{item}}
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

my-component,HTML是少数几个<td></td>data1和呈现的数据data2.

但是在渲染之后,由于<my-component></my-component>我的CSS破坏导致所有my-componentHTML(整个表行)显示在第1列中.

结果如上:

<table>
    <th>
        <td>col 1</td>
        <td>col 2</td>
        <td>col 3</td>
    </th>
    <tr>
        <my-component>
            <td>data1.prop1</td>
            <td>data1.prop2</td>
        </my-component>
    </tr>
    <tr *ngFor="let item of list">
        {{item}}
    </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

我尝试了以下方法:

@Component({
    selector: '[my-component]',
    templateUrl: 'my-component.html'
})

<tr my-component [data1]="data1" [data2]="data2"></tr>
Run Code Online (Sandbox Code Playgroud)

但这会导致错误Can't bind to 'data1' since it isn't …

html css angular-template angular-directive angular

18
推荐指数
1
解决办法
5145
查看次数

标签 统计

angular ×1

angular-directive ×1

angular-template ×1

css ×1

html ×1