Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular 如何把表格里面的tr提出去作为组件 #96

Open
deepthan opened this issue Sep 10, 2020 · 0 comments
Open

Angular 如何把表格里面的tr提出去作为组件 #96

deepthan opened this issue Sep 10, 2020 · 0 comments
Labels

Comments

@deepthan
Copy link
Owner

带有属性选择器的组件

子组件选择器写成属性选择器即可,传值和普通传值一致。

父组件

import {Component } from '@angular/core';
@Component({
  selector: 'app',
  template: `
  <table>
    <tr myTd *ngFor="let animal of animals" [animal]="animal"></tr>
  </table>
  `
})
export class AppComponent {
  animals = [ '猫', '狗' ];
}

子组件

import {Component, Input} from '@angular/core';

@Component({
  selector: '[myTd]',
  template: `<td >{{animal}}</td>`
})
export class MyTdComponent {
  @Input() animal;
}
@deepthan deepthan added the table label Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant