Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angular add object to array

import {Custom} from '../path/to/anyfile.ts'
.....
export class FormComponent implements OnInit {
 name: string;
 empoloyeeID : number;
 empList: Array<Custom> = [];
 constructor() {

 }

 ngOnInit() {
 }
 onEmpCreate(){
   //console.log(this.name,this.empoloyeeID);
   let customObj = new Custom();
   customObj.name = "something";
   customObj.employeeId = 12; 
   this.empList.push(customObj);
   this.name ="";
   this.empoloyeeID = 0; 
 }
}
Comment

angular push in array of objects

import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent  {
  name = 'Angular';
  
  myObjArray = [
    {id: 1, name: "Hardik" },
    {id: 2, name: "Vimal" },
    {id: 3, name: "Paresh" }
  ];
  
  addNew(){
    this.myObjArray.unshift({id: 4, name: "Vimal"});
    console.log(this.myObjArray);
  }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: avascript sleep 1 second 
Javascript :: how to get relative postiion mouse click on element 
Javascript :: javascript load multiple images 
Javascript :: js set url params 
Javascript :: p5.js add class to button 
Javascript :: printf statement in javascript 
Javascript :: JavaScript Using a Temporary Variable 
Javascript :: react native run android 
Javascript :: for each element in object 
Javascript :: what is global execution context in javascript 
Javascript :: useffect compare previous value to current 
Javascript :: access to xmlhttprequest at from origin http localhost:3000 has been blocked by cors policy 
Javascript :: js replace characters in a string 
Javascript :: convert number to string date js 
Javascript :: port 3000 is already in use nodemon app crashed 
Javascript :: iterate object keys javascript 
Javascript :: fillstyle 
Javascript :: first digit javascript 
Javascript :: js check if function exists 
Javascript :: How to fix CSS & JS not loading issue in cPanel laravel 
Javascript :: javascript falsy values 
Javascript :: How to make the width of a react native element adjust according to the contents 
Javascript :: check if number is single digit javascript 
Javascript :: ascending and descending val in array using js 
Javascript :: jquery change text color 
Javascript :: Sort to reverse from an array in javascript 
Javascript :: jq object to dom object convert 
Javascript :: Javascript convert html entity to string 
Javascript :: select add option js 
Javascript :: javascript get random integer in given range 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =