[Solved] Why can’t I access a variable for data binding?

you must have a variable at class level like this export class SampleClass implements OnInit { data: any ; constructor() { } getData() { let request = new XMLHttpRequest(); request.open(‘GET’, ‘https://mywebsite.com/data.json’); request.onload = this.manageData.bind(this); request.send(); } resolveData(ev){ this.data = JSON.parse(ev.target.response); console.log(this.data); } } solved Why can’t I access a variable for data binding?

[Solved] How do I make this javascript in loop?

This is your PHP-loop in javascript. Pretty much the same… Just remember to use the <script> javascript code here </script> tag to tell the browser that this is javascript for (a = 1; a < 2; a++) { //Your stuff inside here } To append HTML to a div you can use the following code: … Read more

[Solved] Variable inside a REGEX

text = input.replace(/(KEYWORD)\(([^)]+)\)/, “$1 $2”) You realize your example has a space after the keyword yeah? Maybe this instead: text = input.replace(/(KEYWORD)\s*\(([^)]+)\)/, “$1 $2”) 2 solved Variable inside a REGEX

[Solved] javascript regex lookahead why abc match? [closed]

You need to handle new lines and you don’t need global search, because capturing must stop only before first abc appearance, so remove m and g flag and add singleline flag s: const str = `test abc abc`; const result = str.match(/.*?(?=abc)/s); console.log(result); 3 solved javascript regex lookahead why abc match? [closed]

[Solved] how to calculate area of polygon on a map? [closed]

From the formula of polygon, Area of ploygon = [(x1y2-x2y1) + (x2y3-x3y2) + …. + (x(n-1)yn – y(n-1)xn)]/2 Try, var arr=[ [10.075854059674523, 76.32832467556], [10.079825860518895, 76.33338868618011], [10.076234340596953, 76.33806645870209], [10.07065684212598, 76.33806645870209], [10.068924417668397, 76.33175790309906] ]; var sum=0; for(var i=0,l=arr.length-1;i<l;i++){ sum+=(arr[i][0]*arr[i+1][1]-arr[i+1][0]*arr[i][1]); } alert(‘The Area of Ploygon is:’+(sum/2)); Demo 6 solved how to calculate area of polygon on a map? … Read more

[Solved] This confuses in javascript [duplicate]

The value of this changes depending upon how the function was invoked; Collection.prototype.onOpen(); // `this` refers to `Collection.prototype` // vs var c = new Collection(); c.onOpen(); // `this` refers to `c` // vs var o = {}; Collection.prototype.onOpen.call(o); // `this` refers to `o` // vs var foo = Collection.prototype.onOpen; foo(); // `this` could be `window` … Read more

[Solved] replace spaces with randam values [closed]

You can use the function rand() : $str = str_replace(‘ ‘, rand(0, 10000), $str); Or did you mean a random value from your list? In this case: $list = array(“value1”, “value2”); $str = str_replace(‘ ‘, array_rand($list, 1), $str); 1 solved replace spaces with randam values [closed]

[Solved] How I can Create many answer [closed]

I hope this answer is what you are looking for: You can make an array with your answers, and then check to see if the given answer is inside the array. const array = [‘test’, ‘test2’, ‘test3’]; if (array.includes(an.value.toLowerCase() ) ) … Something else, you are missing a semicolon in your else { … }. … Read more