2017-04-10 21 views
9

मैं कोणीय 4 में बाल घटक में पैरेंट विधि (हटाएंफोन) को कॉल करना चाहता हूं। मैं इसे ठीक से कैसे कर सकता हूं?एक बच्चे घटक में कोणीय 4 कॉल पैरेंट विधि

मेरे माता-पिता घटक लगता है:

export class ContactInfo implements OnInit { 
    phoneForm: FormGroup; 
    phones: Phone[]; 


    constructor(private fb: FormBuilder, 
      private userService: UserService) { 
    } 

    ngOnInit() { 
     this.userService.getDataPhones().subscribe(
      phones => { 
       this.phones = phones; 
      }); 

     this.phoneForm = this.fb.group({ 
      phone: ['', [Validators.pattern(PHONE_PATTERN)]] 
     }); 
    } 

    deletePhone(phone: Phone) { 
     this.userService.deleteUserPhone(phone) 
      .subscribe(res => { 
       let index = this.phones.indexOf(phone); 
       if (index > -1) { 
        this.phones.splice(index, 1); 
       } 
     }); 
    } 
} 

उत्तर

22
class ChildComponent { 
    @Output() someEvent = new EventEmitter<string>(); 

    callParent() { 
    this.someEvent.next('somePhone'); 
    } 
} 

ContactInfo के टेम्पलेट

<child-component (someEvent)="deletePhone($event)" 
+0

हे में! यह बहुत आसान है, धन्यवाद!)) –

+1

आप इच्छित प्रकार को जोड़ सकते हैं जैसे "नया EventEmitter ()" :) – Nicolas

संबंधित मुद्दे