You need to use Arrow function ()=>
ES6 feature to preserve this
context within setTimeout
.
// var that = this; // no need of this line this.messageSuccess = true; setTimeout(()=>{ // <<<---using ()=> syntax this.messageSuccess = false; }, 3000);
Related Posts:
- What’s the difference between using “let” and “var”?
- Angular: conditional class with *ngClass
- Define a global variable in a JavaScript function
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- What is an unhandled promise rejection?
- Uncaught TypeError: Cannot read property ‘length’ of undefined
- Angular: mat-form-field must contain a MatFormFieldControl
- (change) vs (ngModelChange) in angular
- Cannot find module ‘@angular-devkit/core’
- Why Is `Export Default Const` invalid?
- No value accessor for form control
- Angular: Error no directive with “exportAs” set to “ngForm”
- Angular ForEach in Angular4/Typescript?
- Angular 4 setting selected option in Dropdown
- Angular4 – No value accessor for form control
- Angular: conditional class with *ngClass
- Angular: conditional class with *ngClass
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- What is ViewChild in Angular2?
- Module not found: Error: Can’t resolve ‘fs’ in
- How to fix Cannot find module ‘typescript’ in Angular 4?
- 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
- How do I pass the this context to a function?
- Angular 4 setTimeout() with variable delay and wait
- What does the .subscribe() function do?
- Angular 2 Hover event
- How do I download a file with Angular2 or greater
- What are differences between SystemJS and Webpack?
- How to use forEach loop correctly in angular 2?
- Angular 2 Sort table columns
- How to use onBlur event on Angular2?
- How do I install Angular 2 using NPM?
- clearInterval() not working [duplicate]
- Using Angular 2 without TypeScript Transpiler
- How to convert a string to an integer in JavaScript?
- How do I make the first letter of a string uppercase in JavaScript?
- window.location.href and window.open () methods in JavaScript
- How to create an associative array in JavaScript literal notation
- Include another HTML file in a HTML file
- Cannot open local file – Chrome: Not allowed to load local resource
- How to read a local text file?
- Compare dates with javascript
- Javascript Uncaught SyntaxError: Unexpected identifier
- “document.getElementByClass is not a function”
- How can I create a two dimensional array in JavaScript?
- Short circuit Array.forEach like calling break
- Bootstrap Dropdown menu is not working
- String.prototype.replaceAll() not working
- What does the className attribute mean in JSX?
- How do I check for null values in JavaScript?
- Express Render not working return error: No default engine was specified and no extension was provided
- Remove Object from Array using JavaScript
- What is the difference between ( for… in ) and ( for… of ) statements?
- TypeError: Cannot read property “0” from undefined
- How to use npm jquery module?
- Jquery swipe left or right on mobile
- Sorting arrays in javascript by object key value
- How do I get an element to scroll into view, using jQuery?
- Uncaught SyntaxError: Unexpected token :
- Origin null is not allowed by Access-Control-Allow-Origin
- using jQuery $(this).addClass not working, simple code not working
- onClick to get the ID of the clicked button
- HTML text input allow only numeric input
- How to change the buttons text using javascript
- How to use in jQuery :not and hasClass() to get a specific element without a class
- What is the best way to remove a table row with jQuery?
- Adjust width and height of iframe to fit with content in it
- document.getElementbyId() returning null
- Seeding the random number generator in Javascript
- Bootstrap popover is not working
- Sort array of objects by single key with date value
- Create a simple 10 second countdown
- Generate a Hash from string in Javascript
- jQuery if Element has an ID?
- Get name of object or class
- Complex JSON nesting of objects and arrays
- jQuery – Increase the value of a counter when a button is clicked
- AngularJS POST Fails: Response for preflight has invalid HTTP status code 404
- Getting “Cannot call a class as a function” in my React Project
- Separating html and JavaScript in Flask [duplicate]
- wp.customize.bind ready event not fired
- What does wp-list.js do?
- Preventing YouTube embeds loading multiple instances of player JS?
- How to combine javascript files without plugins?
- WordPress Errors? Update Failed! data.min.js
- Use useSelect/useDispatch instead of withSelect/withDispatch
- Load script after block is inserted
- Trouble adding JavaScript in visual editor (Sharpspring embed code)
- How to set translations in javascripts for my plugin?
- How can I use CKEditor with WordPress and let clients edit the content?
- wp_enqueue_script not loading my custom js file
- Gutenberg getBlockIndex in save() function
- Widgets and Post/Page edit/new blank, console errors only, no server errors
- Add JavaScript-Library “Fitty” to WordPress
- early enqueueing javascript file in page template, not in functions.php
- jQuery + more won’t load in header
- JavaScript errors
- Uncaught ReferenceError: tippy is not defined