0

I was create my component(A). That is combine multiple html element. and I have 2 question.

  1. I don't know how defined method(get, etc..) on my component. I used @Output, @ViewChild, etc.. but it is not working. and I don't wanna develope this way. I need other way.

  2. How can I find my component(A) at home component?

and other question..

  1. how use component focus out event? what to use focus out keyword? (ngFocusOut)? (focusout)? (ngBlur)? (blur)? that is not working..

plz help me!!

mago
  • 39
  • 6
  • 2
    See http://angular.io – Günter Zöchbauer May 24 '16 at 11:37
  • 1&2, you are probably using angular2 the wrong way, it is a data-driven framework. Generally, components don't interact with each other, instead, they interact with services. 3, check [this](http://stackoverflow.com/questions/34799667/angular2-on-focus-event-to-add-class) out and create a minimal example. – Zen May 24 '16 at 11:41
  • http://stackoverflow.com/questions/34522306/angular-2-focus-on-newly-added-input-element – Günter Zöchbauer May 24 '16 at 11:52

1 Answers1

1

You can find you component A on home component by import it in home component

import {componentA} from '/componentA Path/'

About Focus Review this links Angular 2: Focus on newly added input element

Angular 2 set focus to another input

Community
  • 1
  • 1
Muhammad Hassan
  • 475
  • 2
  • 14
  • thank you for your answer. but I need the component Object. import my component and using like this.. and I want abc component object.. – mago May 24 '16 at 12:04
  • After you import it you can use it by creating your object in home class `componentA_Obj : ComponentA;` – Muhammad Hassan May 24 '16 at 12:06
  • I know! but that is not . that is new component A. I don't know how can i find that. – mago May 24 '16 at 12:12
  • you can find your component on html by your selector that you declared in component directive in your home.ts component `@Component({ selector : 'component-selector',})` Then use it in home html component `` – Muhammad Hassan May 24 '16 at 12:14
  • Right! So I use my component at home component. and I want that component-selector tag object! but i don't know!! How can i find that? T-T not HTML Elements object! – mago May 24 '16 at 12:18
  • Ok, you should declare component-selector tag by your self in @component directive, – Muhammad Hassan May 24 '16 at 12:20
  • I will give you a complete example `import {Component} from '@angular/core' import {ComponentA} from 'ComponentA Path' @Component({ selector : 'CA-selector', }) export class ComponentA {}` Then go to your root or home.ts import {Component} from '@angular/core'; import {ComponentA} from './componentA Path/'` @Component({ selector: 'home-app', template: `
    `, directives : [ComponentA] })`
    – Muhammad Hassan May 24 '16 at 12:22
  • above comment to be more cleared in componentA.ts `import {Component} from '@angular/core' import {ComponentA} from 'ComponentA Path' @Component({ selector : 'CA-selector', }) export class ComponentA {}` Then go to your root or home.ts `import {Component} from '@angular/core'; import {ComponentA} from './componentA Path/' @Component({ selector: 'home-app', template: '
    ', directives : [ComponentA] })`
    – Muhammad Hassan May 24 '16 at 12:31
  • thanks your example. but.. sorry my English is not well. my source is exactly same your example. my question is use the ~> in home component. and run the constructor of ComponentA. constructor content is console.log(this);. – mago May 24 '16 at 12:56
  • I wanna control this in console.log(this); from home component. so i need ComponentA object. are you know what i want that? – mago May 24 '16 at 12:58
  • In your home.ts in your homeComponent 1- Create obj from ComponentA 2-you can use it any where `export class homeComponent { CoA_obj : ComponentA; //create obj from Compnent A yourFunction():void{console.log(this.CoA_obj );}}` I hope answered your question. – Muhammad Hassan May 24 '16 at 13:58