Angular 2


Angular2 Databinding All Versions

2.0.0-rc.0
2.0.0-rc.1
2.0.0-rc.2
2.0.0-rc.3
2.0.0-rc.4
2.0.0-rc.5
2.0.0-rc.6
2.0.0-rc.7
2.0.0
2.0.1
2.0.2
2.1.0
2.2.0
2.3.0
2.4.1

This draft deletes the entire topic.

Examples

  • 0

    Parent Component : Initialize users lists.

    @Component({
      selector: 'parent-component',
      template: '<div>
                    <child-component [users]="users"></child-component>
                 </div>'
    })
    export class ParentComponent implements OnInit{
      let users : List<User> = null;
      
      ngOnInit() {
        users.push(new User('A', 'A', '[email protected]');
        users.push(new User('B', 'B', '[email protected]'); 
        users.push(new User('C', 'C', '[email protected]');  
      }      
    }
    

    Child component get user from parent component with Input()


    @Component({
    selector: 'child-component',
      template: '<div>
                      <table *ngIf="users !== null">
                        <thead>
                             <th>Name</th>
                             <th>FName</th>
                             <th>Email</th>   
                        </thead>
                        <tbody>
                            <tr *ngFor="let user of users">
                                <td>{{user.name}}</td>
                                <td>{{user.fname}}</td>
                                <td>{{user.email}}</td>
                            </tr>
                        </tbody>
                      </table>
                    
                 </div>',
    })
    export class ChildComponent {
      @Input() users : List<User> = null;
    }
    
    
    export class User {
      name : string;
      fname : string;
      email : string;
    
      constructor(_name : string, _fname : string, _email : string){
         this.name = _name;
         this.fname = _fname;
         this.email = _email;
      }
    }
    
Please consider making a request to improve this example.

Syntax

Syntax

Parameters

Parameters

Remarks

Remarks

Still have a question about Angular2 Databinding? Ask Question

Topic Outline