Access template reference variables from component class

jackOfAll
<div>
   <input #ipt type="text"/>
</div>

Is it possible to access the template access variable from the component class?

i.e., can I access it here,

class XComponent{
   somefunction(){
       //Can I access #ipt here?
   }
}
mxii

That is a use-case for @ViewChild:

https://angular.io/docs/ts/latest/api/core/index/ViewChild-decorator.html

class XComponent {
   @ViewChild('ipt', { static: true }) input: ElementRef;

   ngAfterViewInit() {
      // this.input is NOW valid !!
   }

   somefunction() {
       this.input.nativeElement......
   }
}

Here's a working demo:

https://stackblitz.com/edit/angular-viewchilddemo?file=src%2Fapp%2Fapp.component.ts

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Access Method from Vue Class Component Decorator inside a Watcher

From Dev

Class Template and Reference Return Type

From Dev

How to access component properties from a Java Class

From Dev

Template Class derived from Non-template base class: No access to base class variables?

From Dev

How to access child class variables from parent class

From Dev

How to access child variables from a parent class?

From Dev

Why is it possible to access private variables from outside class by reference?

From Dev

Angular 2 Component - Access DOM (or create Component without template, purely from JS)

From Dev

Undefined reference to template class destructor

From Dev

Getting a reference to a component in the template

From Dev

PHP reference Class from variable with static method access

From Dev

How to access private static class member inherited from a template class?

From Dev

Gaining access to class members from template specialization

From Dev

Conditional reference declaration in template class

From Dev

Access variables/functions from another Component

From Dev

Access Composite class fields from Component class

From Dev

Class Template and Reference Return Type

From Dev

How to access component properties from a Java Class

From Dev

Accessing variables of a template from another class

From Dev

How to access a generic page class property from a master template

From Dev

How to access child class variables from parent class

From Dev

access variables from class constructor to the class functions in python

From Dev

Access variables from another class in java

From Dev

Unable to access list elements from Flask template variables in JavaScript

From Dev

access state from within component class

From Dev

Access class variables from another class

From Dev

How to access/reference component values inside a component

From Dev

Is there anyway to access variables from one class in another?

From Dev

Template variables are not binding to component variables

Related Related

  1. 1

    Access Method from Vue Class Component Decorator inside a Watcher

  2. 2

    Class Template and Reference Return Type

  3. 3

    How to access component properties from a Java Class

  4. 4

    Template Class derived from Non-template base class: No access to base class variables?

  5. 5

    How to access child class variables from parent class

  6. 6

    How to access child variables from a parent class?

  7. 7

    Why is it possible to access private variables from outside class by reference?

  8. 8

    Angular 2 Component - Access DOM (or create Component without template, purely from JS)

  9. 9

    Undefined reference to template class destructor

  10. 10

    Getting a reference to a component in the template

  11. 11

    PHP reference Class from variable with static method access

  12. 12

    How to access private static class member inherited from a template class?

  13. 13

    Gaining access to class members from template specialization

  14. 14

    Conditional reference declaration in template class

  15. 15

    Access variables/functions from another Component

  16. 16

    Access Composite class fields from Component class

  17. 17

    Class Template and Reference Return Type

  18. 18

    How to access component properties from a Java Class

  19. 19

    Accessing variables of a template from another class

  20. 20

    How to access a generic page class property from a master template

  21. 21

    How to access child class variables from parent class

  22. 22

    access variables from class constructor to the class functions in python

  23. 23

    Access variables from another class in java

  24. 24

    Unable to access list elements from Flask template variables in JavaScript

  25. 25

    access state from within component class

  26. 26

    Access class variables from another class

  27. 27

    How to access/reference component values inside a component

  28. 28

    Is there anyway to access variables from one class in another?

  29. 29

    Template variables are not binding to component variables

HotTag

Archive