angular class functions not working/available when service response is assigned to an array

I have a below class Invoice with some data and methods in it but when I assign REST API array response to my component class array I observe that angular Invoice class methods like addItem, removeItem are not available.

I’ve tried this angular class method not working when populated by service but did not work for me.

Have a look at the below code,

1. Invoice class (angular class)

import { Customer } from "./customer";
import { InvoiceItem } from "./invoice_item";
import { Item } from "./item";

export class Invoice {
    invoiceId?: number;
    invoiceNumber: number;
    
    customer: Customer;
    invoiceItem: InvoiceItem[] = [];

    constructor(customer?: Customer, invoiceNumber?: number) {
        this.customer = customer;
        this.invoiceNumber = invoiceNumber;
        this.invoiceItem.push({itemId: 0, quantity: 0, rate: 0}); // default invoice_item
    }

    addItem() {
        this.invoiceItem.push({itemId: 0, quantity: 0, rate: 0}); // default invoice_item
    }

    removeItem(item) {
        this.invoiceItem.splice(this.invoiceItem.indexOf(item), 1);
    }
    
}

2. Component Class(angular)

import { Component } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { Subject, Subscription } from 'rxjs';
import { Customer } from 'src/app/model/customer';
import { Invoice } from 'src/app/model/invoice';
import { InvoiceService } from 'src/app/services/invoice.service';

@Component({
  selector: 'app-admin-invoices',
  templateUrl: './admin-invoices.component.html',
  styleUrls: ['./admin-invoices.component.css']
})
export class AdminInvoicesComponent {
  customerInvoices: Invoice[] = [];
  customerId: number; 

 
  constructor(private route: ActivatedRoute, 
              private invoiceService: InvoiceService) {
    this.customerId = (this.route.snapshot.paramMap.get('customerId'));

     this.invoiceService.getCustomerInvoices(this.customerId)
      .subscribe((invoices: Invoice[]) => {
        this.customerInvoices = invoices; // assigning service response
      });
  }

}

In the below image you can see service response. Also, we can see the **constructor** of type Object instead of type **Invoice** even if we have declared our customerInvoices array of type Invoice as customerInvoices: Invoice[] = []; in our component class.

service-response

Expected Output is as below:

expected-output

Silent saving image in electron.js

I have got problem with setting path to download files in this case for images. I download image from URL with blob construction like this:

async function downloadImage(imageSrc) {
    const image = await fetch(imageSrc)
    const imageBlog = await image.blob()
    const imageURL = URL.createObjectURL(imageBlog)

    const link = document.createElement('a')
    link.href = imageURL
    link.download = 'asd.png'
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
} 

Then i catch a download signal on main.js like this:

session.defaultSession.on("will-download", (event, item, webContents) => {
        item.setSavePath( /local_dir/ + item.getFilename());
    }) 

When i log getFilename() i have got correct filename what i want, silent also too works because i havent got a window to locate directory of download, but when i look into directory it is empty.

Thanks for help.

When scrolling, stop at certain points

I need to scroll the image with background-position. To create a scrolling effect, I need to set scroll points, all this should happen in a specific block.

I need to create breakpoints, change breakpoints on scroll and assign it to a specific block. How to do it?

Run a script after location is changed, Javascript

I want to achieve something like this,
location.replace("some url"); alert("hello");

I know this won’t work but it runs before the next page is loaded and onload doesn’t seem to work either is there a way to achieve this ? Please just don’t tell there isn’t, although this isn’t a necessity it will be great if I can handle that in my project. THANK YOU

Difference between assigning function to props, with arrow function and without

I don’t understand what is the difference between assigning my handleButton method to the props with and without the arrow function. In React Developer Tools I see only this statement func: f func() {} and func2: f () {}, can you explain me the difference?

Code:

<MathButton
    operator="-"
    number={10}
    func={() => {
        this.handleButton;
    }}
    func2={this.handleButton}
></MathButton>

How can i do automictic Stop the Videos When Play Another Video in laravel site

I’m using YouTube iframe to embed videos on my site developed using php laravel framework. I want to ensure autometic stop others videos when i play one video. I am using following code but not workng it. Can anyone please help me!

<iframe id="youtube_player" class="yt_player_iframe" width="100%" height="350" 
 src="https://www.youtube.com/embed/{{$post->video_link}}" title="YouTube video player" 
 frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; 
 picture-in-picture" allowfullscreen></iframe>

 <script>
  $('.yt_player_iframe').each(function(){
  this.contentWindow.postMessage('{"event":"command","func":"stopVideo","args":""}', '*')
  });
</script>

three.js raycaster mouseover

I’ve been trying to set a “mouseover” effect that gives transparency to the box geometry only, but this applies also on the ground geometry and I’m not able to exclude the ground form this effect, any suggestions on how to achieve this?
I think I need to pass some arguments in intersectObject (scene.somenthing)

import * as THREE from '../../build/three.module.js';
import { OrbitControls } from '../../src/OrbitControls.js';

var controls;

const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const pointer = new THREE.Vector2(1,1);
const raycaster = new THREE.Raycaster();

const renderer = new THREE.WebGLRenderer({alpha:false,antialias:true});
renderer.setSize( window.innerWidth, window.innerHeight );

document.body.appendChild( renderer.domElement );

const light = new THREE.AmbientLight(0x303030);
const dLight = new THREE.DirectionalLight(0xffffff, 0.5);

light.add(dLight);
scene.add(light);

const geometry = new THREE.BoxGeometry(50,0.1,50);
const material = new THREE.MeshPhysicalMaterial( { color: 0x0fa8dc } );
const ground = new THREE.Mesh( geometry, material );

scene.add( ground );
camera.position.set(5,15,15);

controls = new OrbitControls(camera, renderer.domElement);
controls.maxPolarAngle = Math.PI / 2.1; 

//Raycaster reset materials
function resetMaterials() {
    for ( let i = 0; i < scene.children.length; i ++ ) {
        if  (scene.children[i].material) {
            scene.children[i].material.opacity = 1;
        }
    }
}

//raycast hover
function hoverObject() {
    raycaster.setFromCamera( pointer, camera );
    const intersects = raycaster.intersectObjects( scene.children );
    for ( let i = 0; i < intersects.length; i ++ ) {
        intersects[ i ].object.material.transparent = true;
        intersects[ i ].object.material.opacity = 0.75;
    }
}

function animate() {
    controls.update()
    requestAnimationFrame( animate );
    camera.lookAt(ground.position)
    resetMaterials()
    hoverObject()
    renderer.render( scene, camera );

}
animate();

function onWindowResize() {
    camera.aspect = window.innerWidth / window.innerHeight;
    camera.updateProjectionMatrix();
    renderer.setSize( window.innerWidth, window.innerHeight );
    }
   
//on pointer mover
function onPointerMove( event ) {
    pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
    pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;
}

window.addEventListener('resize', onWindowResize); 
window.addEventListener( 'mousemove', onPointerMove, false );

const boxGeometry = new THREE.BoxGeometry(6, 6, 6);
const boxMaterial = new THREE.MeshPhongMaterial( { color: 0xffc000 } );
const box = new THREE.Mesh( boxGeometry, boxMaterial);

box.position.set(0,3,0);

scene.add(box);

Multiply input range value by another number and display result

please how can i multiply the current input range value by 0.95 and display the result in a span tag when button is clicked?

<input id="aaj" type="range" min="{{amountmin}}" max="{{amountmax}}" step="0.003" value="{{amountmin}}">
<button id="aaw" class="aak" onclick="rig();">Range Slider Button</button>
<span class="result"></span>

change javascript let by html click event

<%- include(“partials/header”) %>

this is main page

<% let cpp= 6 %>
<%  for (let i=0;i<cpp;i++){ %>
    <div class="card">
    <li><%= cards[i].name %></li>
    <li><%= cards[i].price %></li>
    <li><%= cards[i].title %></li>
    <li><%= cards[i].inStore %></li>
    <li><%= cards[i].code %></li>
</div>
    <% } %>

button id=”next”>load more

<%- include("partials/footer") %>

how i can change let cpp=6 to cpp=12 on clicking button id=”next”

Expo error while choosing template: Could not get npm url for package

Error:

Laptop:~/Documents/react$ expo init PasswordManager
✔ Choose a template: › blank               a minimal app as clean as an empty canvas
✖ Something went wrong while downloading and extracting the template.
Could not get npm url for package "expo-template-blank"

I am trying to set up React Native in my Linux Mint. I tried using sudo expo init PasswordManager but it was same, I tried doing sudo npm config set registry https://registry.npmjs.org/ and npm install expo-template-blank

Node version: v16.14.0

How to return an Object Value if you have a specific key in your Object? [duplicate]

// If successfully created
let sampleObject = {
response: ‘Generated ID from the application’
}

// If error
let sampleObject = {
errorLog: ‘Generated error message from the application’
}

I have an object that returns different keys depending if it is successful or an error (see above sample code). If it is successful, it has a key of ‘response’ and has a value of ID generated, otherwise it has a key of ‘errorLog’ and has a value of the error message. Now I want to run an if statement with those keys. For example, if the key ‘response’ is present, I want to alert the user for the generated ID for successfully creating the data. But if the key ‘errorLog’ is present, I want to alert the user for the error message.

Can someone help me?

Rearrange divs – Place each div under each image (javascript – jQuery)

I have the following structure example:

<div class="main">
    <div class="image">Image1</div>
    <div class="image">Image2</div>
    <div class="image">Image3</div>
</div>
<div class="side">
    <div class="Banner">Banner1</div>
    <div class="Banner">Banner2</div>
    <div class="Banner">Banner3</div>
    <div class="Banner">Banner4</div>
</div>

I want to make a script that will take each banner and placed under each image.

    <div class="main">
        <div class="image">Image1</div>
        <div class="Banner">Banner1</div>
        <div class="image">Image2</div>
        <div class="Banner">Banner2</div>
        <div class="image">Image3</div>
        <div class="Banner">Banner3</div>
        <div class="Banner">Banner4</div>
    </div>
 <div class="side"></div>

Basically there are some images placed one after another and then some banners placed one after another.

Image1
Image2
Image3
Banner1
Banner2
Banner3
Banner4

I need to take each banner and place it under each image so I can have:

Image1
Banner1
Image2
Banner2
Image3
Banner3
Banner4

I cannot change the html to manually placed the banners, I need to use a more advanced script JS and or jquery ..

.content {display:flex; max-width:800px;min-width:300px;gap:20px;margin:auto;}
.main { flex: 70%;}.main2 {max-width:400px;} 
.side { flex: 30%;  padding:10px;}.img {    background:blue;}.banner {  background:red;}
.img, .banner { width:100%; min-width:50px; height:50px;display:grid;place-items:center;    color: #fff;    margin:10px auto;}
<h2>Rearrange content - Place each div (banner) under each image </h2>
<div class="content">
    <div class="main">
        <div class="img">Image 1</div>
        <div class="img">Image 2</div>
        <div class="img">Image 3</div>
        <div class="img">Image 4</div>
        <div class="img">Image 5</div>
        <div class="img">Image 6</div>
        <p> Multiple DIVs with images ...
        <br>    ...
    </div>
    <div class="side">
        <div class="banner">Banner1</div>
        <div class="banner">Banner2</div>
        <div class="banner">Banner3</div>
        <div class="banner">Banner4</div>
        <div class="banner">Banner5</div>
        <div class="banner">Banner6</div>
        <div class="banner">Banner7</div>
        <div class="banner">Banner8</div>
        <div class="banner">Banner9</div>
        <div class="banner">Banner10</div>
        </div>
    </div>
<hr>
    <h2> This is how it should look </h2>
    <div class="main2">
  <div class="img">Image 1</div>
        <div class="banner">Banner1</div>
        <div class="img">Image 2</div>
        <div class="banner">Banner2</div>
        <div class="img">Image 3</div>
        <div class="banner">Banner3</div>
        <div class="img">Image 4</div>
        <div class="banner">Banner4</div>
        <div class="img">Image 5</div>
        <div class="banner">Banner5</div>
        <div class="img">Image 6</div>
        <div class="banner">Banner6</div>
        <div class="banner">Banner7</div>
        <div class="banner">Banner8</div>
        <div class="banner">Banner9</div>
        <div class="banner">Banner10</div>
    </div>

Is there a way to compress the Chunk that is written to the response?

I want to reduce the size of the response by compressing the chunks written to the API response.
However, I’m not used to working with Node.js, so I’m not sure of the solution or keywords that might be relevant to the solution.


I use Node.js to write chunks in the response, and use it as an arrayBuffer on the client side.

API

const path = req.body.path;

try {
  for await (chunk of stream(path)) {
    res.write(chunk);
  };
  res.status(200).end();
}

Client

const res = await fetch("/api/get-buffer", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ path }),
});
const arrayBuffer = await res.arrayBuffer();

Currently, the above code can be used to get an ArrayBuffer from the API.
However, we would like to reduce the size of the response if it is possible.

Node.js error message while working through tutorial

I am working through https://medium.com/@mbostock/command-line-cartography-part-2-c3a82c5c0f3 but I am hitting this error:

C:tmpgeo-tutorial>ndjson-map -r d3 "(d.properties.fill=d3.scaleSequential(d3.interpolateViridis).domain([0,4000])(d.properties.density),d)" <ca-albers-density.ndjson >ca-albers-color.ndjson C:UserserwinAppDataRoamingnpmnode_modulesndjson-clirequires.js:6 module = require(resolve(module));
           ^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:tmpgeo-tutorialnode_modulesd3srcindex.js from C:UserserwinAppDataRoamingnpmnode_modulesndjson-clirequires.js not supported. Instead change the require of index.js in C:UserserwinAppDataRoamingnpmnode_modulesndjson-clirequires.js to a dynamic import() which is available in all CommonJS modules.
    at module.exports (C:UserserwinAppDataRoamingnpmnode_modulesndjson-clirequires.js:6:12)
    at Command.<anonymous> (C:UserserwinAppDataRoamingnpmnode_modulesndjson-clinode_modulescommanderindex.js:412:13)
    at Command.emit (node:events:390:28)
    at Command.parseOptions (C:UserserwinAppDataRoamingnpmnode_modulesndjson-clinode_modulescommanderindex.js:730:14)
    at Command.parse (C:UserserwinAppDataRoamingnpmnode_modulesndjson-clinode_modulescommanderindex.js:471:21)
    at Object.<anonymous> (C:UserserwinAppDataRoamingnpmnode_modulesndjson-clindjson-map:15:6) {   code: 'ERR_REQUIRE_ESM' }

What does this mean and how can I fix this?

How to create element with absolute position

I want Date to appear above Second section. plz guide how to achieve it

    var sectionTwo = document.getElementById("sectionTwo");
    var x = sectionTwo.getBoundingClientRect();
    var b = document.createElement("div");
    b.style.position = 'fixed';
    b.innerHTML = new Date();
    document.body.appendChild(b);
    b.style.top = (x.top - b.style.height) + 'px';