Posts

Dynalically add megamenu primeng && mapping of nested array

this.restApi.postForm("category_data/?query={label, icon, items{label, icon}}" , '').subscribe(res =>{ this.payload = res; console.log(this.payload); this.items = this.payload.map((element:any) => { let arr = {label : element.label, icon : element.icon, items:[element.items.map((subElement:any)=>{ let suarr = {label : subElement.label, icon : element.icon} return suarr})] } return arr }); console.log("items",this.items) })

Json Array

var orders = [ { "id": 5, "created": "2021-05-15T13:22:16.679697+05:30", "modified": "2021-05-15T14:59:11.141495+05:30", "label": "dfrf", "url_slug": null, "thumbnail": null, "icon": "icodn_1", "description": "sjksjhgsjg", "status": true, "category": 5 }, { "id": 2, "created": "2021-05-15T12:27:47.798769+05:30", "modified": "2021-05-15T12:27:47.798769+05:30", "label": "ewaste", "url_slug": null, "thumbnail": null, "icon": null, "description": null, "status": true, "category": 5 }, { "id": 3, "created": "2021-05-15T12:53:54.935037+05:30", "modified": "2021-05-15T12:53:54.935037+05:30", "label": "fan2", "url_s...

On scroll scroll hover animation Angular

In View or HTML // Lorem ipsum dolor sit amet consectetur adipisicing elit. Doloribus, reprehenderit? //in TS import { trigger, state, style, animate, transition } from '@angular/animations'; // decalre 2 styles 1 for show and one for hide const style1 = style({ opacity: 1, transform: "translateX(0)" }) const style2 = style({ opacity: 0, transform: "translateX(-100%)" }) //in animation animations: [ trigger('foobar', [ state('show', style1), state('hide', style2), transition('show => hide', animate('700ms ease-out')), transition('hide => show', animate('700ms ease-in')) ]) ] }) // make default state = hide; //check if scroll is on element; @HostListener('window:scroll', ['$event']) checkScroll() { const componentPosition = this.el.nativeElement.offsetTop const scrollPosition ...

JSON array filter

// create new array myarray: any = []; //consider ourPartnersData is your Json array this.myArr = this.ourPartnersData.filter(function (el) { return el.vc_partner_type == 'digital' }); console.log("new ",this.myArr)

Convering object into Array

//this is your object let myObj = {CountryID: 87944818, ISO2: "do", ISO3: "u", Name: "aliqua sit magna tempor"} // create an empty array let myArr = []; // push your object into arry myArr.push(myObj); //check using type of method console.log(myArr);

[ngStyle] property binding (image) [ngStyle] image binding not working

//use like below - you should add url() within that use your value as property binding //note don't write your value as string.

The maxlength attribute is not working with number

If the value of the type attribute is text, email, search, password, tel, or url, this attribute specifies the maximum number of characters (in Unicode code points) that the user can enter; for other control types, it is ignored. So maxlength is ignored on by design. Depending on your needs, you can use the min and max attributes as inon suggested in his/her answer (NB: this will only define a constrained range, not the actual character length of the value, though -9999 to 9999 will cover all 0-4 digit numbers), or you can use a regular text input and enforce validation on the field with the new pattern attribute: