Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
Yes, that’s it. In the app.module.ts file, I just added: import { FormsModule } from ‘@angular/forms’; […] @NgModule({ imports: [ […] FormsModule ], […] })
Yes, that’s it. In the app.module.ts file, I just added: import { FormsModule } from ‘@angular/forms’; […] @NgModule({ imports: [ […] FormsModule ], […] })
In ES6 using Array from() and keys() methods. Array.from(Array(10).keys()) //=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Shorter version using spread operator. […Array(10).keys()] //=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Start from 1 by passing map function to Array from(), with an object with a length property: Array.from({length: … Read more
Here’s how I would do it: if (Object.prototype.toString.call(d) === “[object Date]”) { // it is a date if (isNaN(d)) { // d.getTime() or d.valueOf() will also work // date object is not valid } else { // date object is valid } } else { // not a date object } Update [2018-05-31]: If you … Read more
Use native JSON.stringify method. Works with nested objects and all major browsers support this method. str = JSON.stringify(obj); str = JSON.stringify(obj, null, 4); // (Optional) beautiful indented output. console.log(str); // Logs output to dev tools console. alert(str); // Displays output using window.alert() Link to Mozilla API Reference and other examples. obj = JSON.parse(str); // Reverses … Read more
Most of the jQuery Ajax methods return an XMLHttpRequest (or the equivalent) object, so you can just use abort(). See the documentation: abort Method (MSDN). Cancels the current HTTP request. abort() (MDN). If the request has been sent already, this method will abort the request. var xhr = $.ajax({ type: “POST”, url: “some.php”, data: “name=John&location=Boston”, … Read more
There are a lot of details in the File System API. The most common way is: const fs = require(‘fs’); fs.writeFile(“/tmp/test”, “Hey there!”, function(err) { if(err) { return console.log(err); } console.log(“The file was saved!”); }); // Or fs.writeFileSync(‘/tmp/test-sync’, ‘Hey there!’);
If typeof yourVariable === ‘object’, it’s an object or null. If you want null, arrays or functions to be excluded, just make it: if ( typeof yourVariable === ‘object’ && !Array.isArray(yourVariable) && yourVariable !== null ) { executeSomeCode(); }
Use the find() method: myArray.find(x => x.id === ’45’).foo; From MDN: The find() method returns the first value in the array, if an element in the array satisfies the provided testing function. Otherwise undefined is returned. If you want to find its index instead, use findIndex(): myArray.findIndex(x => x.id === ’45’); From MDN: The findIndex() … Read more
Close chrome (or chromium) and restart with the –disable-web-security argument. I just tested this and verified that I can access the contents of an iframe with src=”http://google.com” embedded in a page served from “localhost” (tested under chromium 5 / ubuntu). For me the exact command was: Note : Kill all chrome instances before running command … Read more
There are several ways of checking if an variable is an array or not. The best solution is the one you have chosen. variable.constructor === Array This is the fastest method on Chrome, and most likely all other browsers. All arrays are objects, so checking the constructor property is a fast process for JavaScript engines. … Read more