It provides a reference to elements or components in your view:
@Component({ ... directives: [SomeComponent], template: ` <div><span #myVar>xxx</span><div> <some-comp></some-comp>` }) class MyComponent { @ViewChild('myVar') myVar:ElementRef; @ViewChild(SomeComponent) someComponent:SomeComponent; ngAfterViewInit() { console.log(this.myVar.nativeElement.innerHTML); console.log(this.someComponent); } }
IMPORTANT: The variables are not initialized before ngAfterViewInit()
Related Posts:
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Angular: mat-form-field must contain a MatFormFieldControl
- (change) vs (ngModelChange) in angular
- Angular ForEach in Angular4/Typescript?
- Angular4 – No value accessor for form control
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- Angular 4 setTimeout() with variable delay and wait
- How do I download a file with Angular2 or greater
- Angular 2 Sort table columns
- How do I install Angular 2 using NPM?
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- ES6 Map in Typescript
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Angular: conditional class with *ngClass
- How to define type for a function callback (as any function type, not universal any) used in a method parameter
- TypeScript foreach return [duplicate]
- TypeScript React.FC
confusion - What is an unhandled promise rejection?
- How to perform string interpolation in TypeScript?
- Typescript : Property does not exist on type ‘object’
- Cannot find module ‘@angular-devkit/core’
- No value accessor for form control
- Angular: Error no directive with “exportAs” set to “ngForm”
- Angular 4 setting selected option in Dropdown
- Angular: conditional class with *ngClass
- Possible to extend types in Typescript?
- No overload matches this call. Type ‘string’ is not assignable to type ‘Signals’
- RegExp in TypeScript
- How do you format a Date/Time in TypeScript?
- Angular: conditional class with *ngClass
- How do I check whether an array contains a string in TypeScript?
- Module not found: Error: Can’t resolve ‘fs’ in
- Uncaught ReferenceError: define is not defined typescript
- Angular 2 – Using ‘this’ inside setTimeout
- How to fix Cannot find module ‘typescript’ in Angular 4?
- String.Format not work in TypeScript
- declaration or statement expected javascript/typescript
- TypeError: Class extends value undefined is not a function or null
- Can’t perform a React state update on an unmounted component
- How to set Angular 4 background image?
- SyntaxError: Unexpected token C in JSON at position 0 – Ionic 2 Http GET request
- Crop the image using JavaScript
- What does the .subscribe() function do?
- Angular 2 Hover event
- What are differences between SystemJS and Webpack?
- typescript – cloning object
- How to use forEach loop correctly in angular 2?
- How to use onBlur event on Angular2?
- Using Angular 2 without TypeScript Transpiler
- Failed to load resource: the server responded with a status of 404 (Not Found)
- What is NODE_ENV and how to use it in Express?
- How to deal with net::ERR_SSL_PROTOCOL_ERROR?
- What is the way of declaring an array in JavaScript?
- How to disable JavaScript in Chrome Developer Tools?
- Reactjs – Form input validation
- What is event bubbling and capturing?
- JS – ReferenceError: fetch is not defined
- Check if a variable is a string in JavaScript
- How can I add a key/value pair to a JavaScript object?
- Adding an onclick event to a div element
- Use images like checkboxes
- What is the difference between document.location.href and document.location?
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- Preloading images with JavaScript
- How to print elements from array with javascript
- What is the JavaScript version of sleep()?
- How do I scroll to an element using JavaScript?
- How to loop through an array containing objects and access their properties
- Expected linebreaks to be ‘LF’ but found ‘CRLF’ linebreak-style
- Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH
- How does += (plus equal) work?
- Javascript Comparison Operators != vs !==
- onEnter not called in React-Router
- Find the largest palindrome made from the product of two 3-digit numbers – Javascript
- Javascript/Jquery Convert string to array
- How to interpolate variables in strings in JavaScript, without concatenation?
- How to add a keyboard listener to my onClick handler?
- Bootstrap modal – close modal when “call to action” button is clicked
- Javascript: difference between a statement and an expression?
- JavaScript string encryption and decryption?
- How to dequeue a script?
- How to use wp_localize_script in custom page template?
- preserve url parameters from affliliate sites
- How to overwrite JS variable with wp_localize _script?
- How to get value of selected page template in Gutenberg editor?
- Conditional fields in contact form 7 not working
- How to place script in footer?
- Enqueueing a script and a style sheet not working
- AngularJS with route and JSON API
- Use onfocus event in Contact Form 7
- Get Block Attributes in JSON REST API
- enqueue script won’t work (enqueue style does work)
- Variable equals another variable and then equals another variable
- in jquery read a multidimensional array via wp_localize_script()
- Custom JS on a specific page
- How to get file object from file_attachment?
- How do I load urls from an external .js file to my admin head?
- Where is the Javascript attribute window._wpCustomHeaderSettings defined?
- how to include js in widget?
- JS files landing on page but not working, using childtheme of twentyeleven