Why won’t my array display correctly with Angular?

I’m trying to display data using a parent to child relationship with Angular, however I am having issues and am not sure why. I’m trying to display an array of Employee objects, but when I run the webpage on localhost, it displays it as:

[object Object]
[object Object]
[object Object]
[object Object]
[object Object]

The goal is to inject an Employee service into my EmployeeList componet (parent) and display it using DisplayEmployee (child) component. I can see the data I want being passed through in the console, but not on the webpage. How can I fix this issue, and why does it not recognize the data I’m trying to pass through?

Employee class:

export class Employee {
  private _firstName: string;
  private _lastName: string;
  private _salary: number;
  private _department: string;

  constructor(firstName: string, lastName: string, salary: number, department: string) {
    this._firstName = firstName;
    this._lastName = lastName;
    this._salary = salary;
    this._department = department;
  }

  get firstName(): string {
    return this._firstName;
  }

  get lastName(): string {
    return this._lastName;
  }

  get salary(): number {
    return this._salary;
  }

  get department(): string {
    return this._department;
  }
}

Employee Service:

import { Injectable } from '@angular/core';
import {Employee} from "./employee";

@Injectable({
  providedIn: 'root'
})
export class EmployeeService {
  private _employees: Employee[];

  constructor() {
    this._employees = [];
    this.populateEmployees();
  }

  private populateEmployees(): void {
    this._employees.push(new Employee("Kyle", "Ryan", 250_000, "Management"));
    this._employees.push(new Employee("John", "Smith", 50_000, "Human Resources"));
    this._employees.push(new Employee("Nicole", "Berg", 200_000, "Management"));
    this._employees.push(new Employee("Bryan", "Jones", 90_000, "Customer Support"));
    this._employees.push(new Employee("Sarah", "Little", 50_000, "Customer Support"));
  }

  get employees(): Employee[] {
    return this._employees;
  }
}

EmployeeList component (parent):

import { Component, OnInit } from '@angular/core';
import {EmployeeService} from "../services/employee.service";

@Component({
  selector: 'app-employee-list',
  templateUrl: './employee-list.component.html',
  styleUrls: ['./employee-list.component.css']
})
export class EmployeeListComponent implements OnInit {
  private _allEmployees: any;

  constructor(private employeeService: EmployeeService) { }

  ngOnInit(): void {
    this._allEmployees = this.employeeService.employees;
  }

  get allEmployees(): any {
    return this._allEmployees;
  }
}

DisplayEmployee component (child):

import { Component, OnInit, Input } from '@angular/core';

@Component({
  selector: 'app-display-employee',
  templateUrl: './display-employee.component.html',
  styleUrls: ['./display-employee.component.css']
})
export class DisplayEmployeeComponent implements OnInit {
  @Input() list: any = "";

  constructor() { }

  ngOnInit(): void {
  }

}

EmployeeList component template:

<app-display-employee [employeeList]=allEmployees></app-display-employee>

DisplayEmployee component template:

<div>
  <table>
    <tr *ngFor="let emp of employeeList;">
      <td>{{ emp }}</td>
    </tr>
  </table>
</div>

I have a problem fetching data from codeforces to my github profile

I have a problem fetching data from codeforces to my github profile I can’t add a js code to the readme.md file to fetch data from codeforces
When I’m trying to write a js code like this it appears as a text.

    <script>
      
fetch('https://codeforces.com/api/user.status?handle=sadeen&from=1&count=10').then(response => response.json()).then(characters => showCharacters(characters.results));
  showCharacters = characters => {
  const charactersDiv = document.querySelector(‘#rick-and-morty-  characters’);
  characters.forEach(character => {
    const characterElement = document.createElement(‘p’);
    characterElement.innerText = `Character Name: ${character.name}`;
    charactersDiv.append(characterElement);
  });
}
    </script>

Change the argument of a function that is inside another function

This are my tasks:

This is my tasks

As you can see, they all have “same” logic.
So I wanted use function like this ->

const task71=(x)=>Math.tan(2*x+x*x);
const main=(x,dX,xEnd)=>{
  while(x<=xEnd)
  {
    task71(x); //this part I wanna change, so it will work for task72,task73...
    x+=dX;
    console.log(`Y=${task71(x)}nX=${x}`);
  }
}

This works only for task71(x),but I have task72(x),task73(x),etc. What do I need to change in
main(x,dx,xEnd) function to make it work for another functions?
I tried use task71(x) as argument, but in this way the function only works with the initial value of x.

Perhaps this question is stupid, sorry, I recently started learning programming.

switch between automatic slideshows

I’m doing a web application (.NET CORE+Angular) and I need to have three automatic slideshows (whole screen, 10 different images each) and to change a slidershow, user needs to use arrows on keyboard.
I’m not sure how should I accomplish it. I can create one slidershow and use arrows to switch images, but not between automatic slidershows. Any ideas?

Sort Option children by index value for both parent Selects (Javascript Only)

I’m trying to create a Dual List Box using only vanilla Javascript, no JQuery or JS packages, for learning purposes.

When a user double-clicks an Option, that Option appends to the other parent Select (boxB) and is removed from the original parent Select (boxA), and vice versa. The Option elements have data-index attributes with ascending numerical values. How do I maintain the numerical order of the Options by index value, regardless of which parent Select they append?

<!-- HTML -->
<select id="ctst1" class="form-control form-control-sm" size="8" multiple>
    <option data-index="1" value="CPT">CPT</option>
    <option data-index="2" value="SST">SST</option>
    <option data-index="3" value="EDTA">EDTA</option>
    <option data-index="4" value="PAXgene">PAXgene</option>
    <option data-index="5" value="NP SWB">NP SWB</option>
    <option data-index="6" value="OP SWB">OP SWB</option>
    <option data-index="7" value="RCTL SWB">RCTL SWB</option>
    <option data-index="8" value="Self NS">Self NS</option>
</select>
<select id="ctst2" class="form-control form-control-sm" size="8" multiple></select>

// Javascript
const dataFrame = {
    "selCollTubeSampTypes": [
        ["CPT", "CPT"],
        ["SST", "SST"],
        ["EDTA", "EDTA"],
        ["PAXgene", "PAXgene"],
        ["NP SWB", "NP SWB"],
        ["OP SWB", "OP SWB"],
        ["RCTL SWB", "RCTL SWB"],
        ["Self NS", "Self NS"]
    ]
};

function dualListBox(qryId1, qryId2, dataset) {
    const boxA = document.getElementById(qryId1);
    const boxB = document.getElementById(qryId2);
    // Populate avail box with data
    for (let i = 0; i < dataset.length; i++) {
        const eleOption = document.createElement("option");
        eleOption.dataset.index = i + 1; // Adds data-index value to Option node
        if (dataset[i][0] === "") {
            eleOption.textContent = dataset[i][1];
        } else {
            eleOption.value = dataset[i][0];
            eleOption.textContent = dataset[i][1];
        };
        boxA.appendChild(eleOption);
    };
    // When option in Box A is double-clicked, move it to Box B
    boxA.addEventListener("dblclick", e => {
        let eTargetOpt = e.target.closest("option");
        if (!eTargetOpt) return;
        if (!boxA.contains(eTargetOpt)) return;
        if (eTargetOpt) {
            boxB.appendChild(eTargetOpt);
            boxB.selectedIndex = "-1";
            boxA.removeChild(eTargetOpt);
        };
        e.stopPropagation();
    }, false);
    // When option in Box B is double-clicked, move it to Box A
    boxB.addEventListener("dblclick", e => {
        let eTargetOpt = e.target.closest("option");
        if (!eTargetOpt) return;
        if (!boxB.contains(eTargetOpt)) return;
        if (eTargetOpt) {
            boxA.appendChild(eTargetOpt);
            boxA.selectedIndex = "-1";
            boxB.removeChild(eTargetOpt);
        };
        e.stopPropagation();
    }, false);

dualListBox("ctst1", "ctst2", dataFrame.selCollTubeSampTypes);

how to iterate a type from typescript and use it to form another type

I wrap my api request to an obj with moduleName and apiName with url values like

const modules = {
  cart: {
    cart: '/shoppingCart',
    goodsSkus: '/shoppingCart/goodsSkus',
  },
}

And i use a helperFunction below to convert it to my apiActionObject

now this is from from js file, because my ts file is on error.

let apiAction = {};
Object.keys(modules).forEach((modulesName) => {
  apiAction[modulesName] = {};
  Object.keys(modules[modulesName]).forEach((apiName) => {
    apiAction[modulesName][apiName] = async ({
      method = 'get',
      id,
      resource,
      ...options
    } = {}) => {
      let url = modules[modulesName][apiName];
      url += `${id !== undefined ? `/${id}` : ''}${
        resource ? `/${resource}` : ''
      }`;

      return service({ url, method, ...options });
    };
  });
});

And i try to make my ApiAction type using code below, everythink looks well.

type ModuleName = keyof typeof modules;
type ApiName<T extends ModuleName> = keyof typeof modules[T];

type ApiAction = {
  [moduleName in ModuleName]: {
    [apiName in ApiName<moduleName>]: (
      arg: ApiServiceParams<any, any>
    ) => Promise<any>;
  };
};

Then i try to add some more specific type in ApiServiceParams, below code goes wrong

// requestAndResponseType
type _RRType = {
  [moduleName in ModuleName]: {
    [apiName in ApiName<moduleName>]: {
      req: any;
      res: any;
    };
  };
};

interface RRType extends _RRType {
  cart: {
    cart: {
      req: Api.GetPvStatsUsingGetParams;
      res: Api.AfterSaleTicketPageResponse;
    };
    goodsSkus: {
      req: Api.GetPvStatsUsingGetParams;
      res: Api.AfterSaleTicketPageResponse;
    };
  };
}


type TypeWorksFine = RRType['goods']['product']['req']; // type is any
type TypeWorksFine2 = RRType['cart']['goodsSkus']['req']; // type is Api.GetPvStatsUsingGetParams;

// https://stackoverflow.com/questions/46846669/type-key-cannot-be-used-to-index-type-object
type ApiAction = {
  [moduleName in ModuleName]: {
    [apiName in keyof RRType[moduleName]]: (
      arg: ApiServiceParams<RRType[moduleName][apiName]['req'], any>
    ) => Promise<any>;
  };
};

The code above is both type TypeWorksFine and TypeWorksFine2 works properly, but in the interation of ApiAction, it fails with error Type ‘”req”‘ cannot be used to index type ‘RRType[moduleName][apiName]’.

In fact i first ran into this error when i use the key as [apiName in ApiName] as below

type ApiAction = {
  [moduleName in ModuleName]: {
    [apiName in ApiName<moduleName>]: (
      arg: ApiServiceParams<RRType[moduleName][apiName], any> // Type 'apiName' cannot be used to index type 'RRType[moduleName]'
    ) => Promise<any>;
  };
};

then i found a tip to fix this type key cannnot be used to index type object answer to solve this problem.
but when i get in this problem by the req property, i can’t find a way to fix.

So there is a way to iterate the type object and make the new type? Thank you in advance!

protoype js 1.0.6 is conflicting with chart js

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--<script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.6.0.3/prototype.min.js"></script> -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script>
</head>
<body>
    
    <canvas id="myChart" width="100" height="200"></canvas>
    <script>
        window.onload = () => {
            let myElm = document.createElement("script");   // Create a new element

            myElm.src = 'https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.min.js';
            myElm.setAttribute ('defer' ,true); // Change the text of the element
            myElm.setAttribute ('type'  ,'module'); // Change the text of the elementù
            //document.querySelector('head').prepend(myElm);    // Add the object to the DOM
        }
        let jq =  jQuery.noConflict()
    </script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/prototype/1.7.3/prototype.min.js"></script>
<script type="text/javascript" defer >
var ctx = document.getElementById('myChart').getContext('2d');
document.addEventListener("DOMContentLoaded", function(event) {
    console.log(Prototype.Version);
var myChart = new Chart(ctx, {
    type: 'bar',
    data: {
        labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
        datasets: [{
            label: '# of Votes',
            data: [12, 19, 3, 5, 2, 3],
            backgroundColor: [
                'rgba(255, 99, 132, 0.2)',
                'rgba(54, 162, 235, 0.2)',
                'rgba(255, 206, 86, 0.2)',
                'rgba(75, 192, 192, 0.2)',
                'rgba(153, 102, 255, 0.2)',
                'rgba(255, 159, 64, 0.2)'
            ],
            borderColor: [
                'rgba(255, 99, 132, 1)',
                'rgba(54, 162, 235, 1)',
                'rgba(255, 206, 86, 1)',
                'rgba(75, 192, 192, 1)',
                'rgba(153, 102, 255, 1)',
                'rgba(255, 159, 64, 1)'
            ],
            borderWidth: 1
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});

});
</script>

</body>
</html>

So if you will remove comment from
https://cdnjs.cloudflare.com/ajax/libs/prototype/1.6.0.3/prototype.min.js
script tag it will stop working and show error in console

x-axios 0.undefined

  1. I tried to add me prototype on project it is inside code will it is still conflicting even I also tried noConflict method in jquery

How to return array of objects by checking its property and arraylist in javascript

how to compare array of objects with arrays using javascript

I need to check array of objects based on conditons

  1. if the targetvalue is same and code does not have value in arraylist return array of objects

  2. else if the targetvalue is same and code same value in arraylist return array of objects

else return []

var arraylist =["IT","FI"];
var arrobj1 =[
  {id:1, name: "sonu", code: "IT", targetvalue: "908"},
  {id:2, name: "abi", code: "IT", targetvalue: "834"},
  {id:3, name: "lisa", code: "SP", targetvalue: "834"},
  {id:4, name: "ben", code: "FI", targetvalue: "234"},
]

Expected Output 
//same value , and has "IT" 
[]

****

var arrobj2 =[
  {id:1, name: "sonu", code: "IT", targetvalue: "908"},
  {id:2, name: "abi", code: "IT", targetvalue: "834"},
  {id:3, name: "lisa", code: "SG", targetvalue: "234"},
  {id:4, name: "ben", code: "SP", targetvalue: "234"},
]

Expected Output
//same targetvalue and no include of `FI or IT` so return
[
 {id:3, name: "lisa", code: "SG", targetvalue: "234"},
  {id:4, name: "ben", code: "SP", targetvalue: "234"},
] 


****

var arrobj3 =[
  {id:1, name: "sonu", code: "IT", targetvalue: "908"},
  {id:3, name: "lisa", code: "FI", targetvalue: "234"},
  {id:4, name: "ben", code: "FI", targetvalue: "234"},
]
Expected Output
// targetvalue and code same
 [ {id:3, name: "lisa", code: "FI", targetvalue: "234"},
  {id:4, name: "ben", code: "FI", targetvalue: "234"}]

I tried

const checkIdList = list => {
    const idlist = ['IN', 'FI'];
    const resultarray = list
      .map((obj, i) => list.find((elem, index) => {
        if (i !== index && elem.targetvalue === obj.targetvalue && 
           (element.code === obj.code || idlist.includes(element.code)) {
          return obj;
        }
      }))
      .filter(x => x);
    return resultarray;
  };
var finalResult = this.checkIdList(arrobj1);
  
  

Error Uncaught TypeError: Cannot read properties of null (reading ‘addEventListener’) in a separeted file

This error keep showing to me only if a put this JavaScript code in a separeted file, and link to my Html… If they are insede a tag they work just fine…

script.js:4 Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')

Html:

<div class="navbarr__toggle" id="mobile-menu">
                <span class="barr"></span>
                <span class="barr"></span>
                <span class="barr"></span>
            </div>
            <ul class="navbarr__menu">
                <li class="navbarr__item">
                    <a href="#me" class="navbarr__links"><span>01. &nbsp;</span> About me </a>
                </li>
                <li class="navbarr__item">
                    <a href="#work" class="navbarr__links"><span>02. &nbsp;</span> Projects</a>
                </li>
            </ul>

JavaScript:

console.log("out of script");
let menu = document.querySelector('#mobile-menu');
let menuLinks = document.querySelector(".navbarr__menu");
menu.addEventListener('click', function(){
    console.log("!I here");
    menu.classList.toggle('is-active');
    menuLinks.classList.toggle('active');
    
})

What can be the issue here? note that I alredy link the .Js file to my .Html…

How to detect if the scroll bar reached the end using JavaScript

I’m trying to implement a feature in a terms and conditions page where the Agree button will be disabled until the user scrolls over all the conditions till the end. So, I tried to follow an existing example (http://jsfiddle.net/dy8bqzkm/) and change what best fits into my scenario, but I keep facing issues and errors. Any idea on how to implement this feature correctly?

Error message:
Error Message

HTML code:

<div class="container w-container">
      <div class="termsdiv">
        <div class="policy-section" style="max-height: 250px; overflow-y: auto;" 
             id="PolicySection">

          <!-- Policy conditions are listed here between list and paragraph tags-->
        
        </div>
      </div>
    
      <div class="buttonblok">
        <button type="submit" class="agree w-button" id="AgreeBtn" disabled>I Agree</button>
        <button type="submit" class="cancel w-button" id="CancelBtn">Cancel</button>
      </div>
    
    </div>

JavaSript code:

<script>
    document.getElementsById("PolicySection")[0].addEventListener("scroll", checkScrollHeight, 
    false);

    function checkScrollHeight() {
        var policyElement = document.getElementsById("PolicySection")[0]
        if ((policyElement.scrollTop + policyElement.offsetHeight) >= policyElement.scrollHeight) 
        {
            document.getElementsById("AgreeBtn")[0].disabled = false;
        }
    }
 </script>

How do i display data only on the clicked card?

[before click][1]

https://i.stack.imgur.com/cfvUT.png

[after click ][2]

https://i.stack.imgur.com/ISXAU.png

Hello noobie is stuck again. so i’ve fetched all these workouts and rendered them in my template. When clicking on the details button more data shows up but the problem is that all buttons get activated but i only want to open the one i click on. I guess i need to target the right id but noting i have tried works :/

    <div class="wrapper">
      <div class="workouts" v-for="workout in workouts" :key="workout.id">
        <div class="card-item-container">
          <img v-if="mens" :src="workout.male.image" />
          <img v-else :src="workout.female.image" />
        </div>
        <div class="card-item-content">
          <h3>{{ workout.name }}</h3>
          <button @click="showModal = true">Details</button>
        </div>
 
        <div class="modal" v-if="showModal">
          <h3>
            Mouscle groups: {{ workout.bodyAreas[0] }}
            {{ workout.bodyAreas[1] }}
          </h3>
          <b v-html="workout.transcript"> </b>
          <button class="close" @click="showModal = false">close</button>
        </div>
<script>
export default {
  components: {},
  data() {
    return {
      mens: true,
      womens: true,
      showModal: false,
    };
  },

  methods: {
    toggleMens() {
      this.mens = true;
      this.womens = false;
    },
    toggleWomens() {
      this.womens = true;
      this.mens = false;
    },
  },

  computed: {
    workouts() {
      return this.$store.state.workouts;
    },
  },

  async mounted() {
    await this.$store.dispatch("fetchWorkouts");
  },
};
</script>

On scroll second div covers a fixed div which contains a centered picture and meanwhile a grey frame appears in place of the picture

I’m totally stuck with the fallowing task:
I need to achieve the same layout as on the attached GIF.
I have a fixed div and a picture in the middle of that div.
The second dive goes in front of the first one.
But as you scroll and the second div covers the first one a fixed gray frame remains in place of the picture. See the .GIF attached! I have no idea how to put that gray frame there…
I appreciate any kind of help, advice, solution! Thanks a lot!


—> https://i.stack.imgur.com/seW6P.gif <—