How to get Token of mvc in angular 6/ angular 9

 How to get Token of mvc in angular 6/ angular 9



For calling MVC Token we are divide process into three steps:-

Step1:-

getCSharpMVCToken(userData) {

    return new Promise((resolve, reject) => {

      const data = {

        'userName': this.loginForm.get('userName').value,

        'password': userData.uuid

      };

      this.authService.getCSharpMVCToken(data).then(tokenRes => {

        // this.userService.saveUserActivityLog(Constants.USER_ACTIVITIES.USER.NAME, Constants.NO_COMMENTS,

        //   Constants.USER_ACTIVITIES.OPERATIONS.LOGIN, Constants.NO_COMMENTS);

        return resolve(true);

      }).catch(err => {

        this.toggleSpinner(false);

        this.authService.logout();

        return reject(false);

      });

    });

  }

  

Step2:-

getCSharpMVCToken(data): Promise<any> {

        return new Promise((resolve, reject) => {

            if (this.alfAuthuthService.isEcmLoggedIn()) {

                this.apiService.getCSharpMVCToken(environment.CSharpMVCTokenApi, data).subscribe((res: any) => {

                    this.browserStorageService.setLocalStorageItem('CSharpMVCToken', res['access_token']);

                    return resolve(res);

                }, (err) => {

                    reject(err);

                });

            } else {

                reject(false);

            }


        });

           }

Step1:-

getCSharpMVCToken(URL, user: any) {

    const userData = 'username=' + user.userName + '&password=' + user.password + '&grant_type=password';

    const reqHeader = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded' });

    const response = this.http.post(URL, userData, { headers: reqHeader }).pipe(map((res => {

      return res;

    })), catchError((error: any) => {

      return this.httpErrorHandler.handleError('api-service', error, URL);

    }));


    return response;

  }



How to solved ngx-multiselect in angular cause long page scroll when we select item of it

How to solved ngx-multiselect in angular cause long page scroll when we select item of it



For solving this issue please put css on it


.dropdown-list{
    display:grid;
}

it just stop scroll of page

How to Create excel file and download it or convert into base64 string

How to Create excel file and download it or convert into base64 string

1).First Install Following packages from Node module
1).npm install exceljs
page Url:https://www.npmjs.com/package/exceljs
2).npm install file-saver --save
page Url:https://www.npmjs.com/package/file-saver
Code Writing:-


import * as Excel from 'exceljs/dist/exceljs';
import * as FileSaver from 'file-saver';
import { Injectable } from '@angular/core'; @Injectable({
providedIn: 'root', }) export class HeroService { constructor() { }
public generateExcel(paramData: any, _ReferenceNo, IsSend = false): any { return new Promise((resolve, reject) => { if (IsSend) { return this.workbook.xlsx.writeBuffer({ base64: true }).then((data) => { const itemdata = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" }); const reader = new FileReader(); reader.readAsDataURL(itemdata); reader.onloadend = function () { return resolve(reader.result.toString().replace('data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,', '')); } }); } else { this.workbook.xlsx.writeBuffer().then((data) => { const blob = new Blob([data], { type: EXCEL_TYPE }); FileSaver.saveAs(blob, _ReferenceNo ? _ReferenceNo : 'temporary' + EXCEL_EXTENSION); return resolve(data); }); } }); }
}
Calling Method to component:- 


this.pdfService.generatePDF(this.trademodel, true, false).then(resp=>{
postJson.PdfString=resp;
});





How to Create pdf file and download it or convert into base64 string

 

How to Create pdf file and download it or convert into base64 string


1).First Install Following packages from Node module
1).npm install jspdf --save
page Url:https://www.npmjs.com/package/jspdf
2).npm install jspdf jspdf-autotable
page Url:https://www.npmjs.com/package/jspdf-autotable
Code Writing:-


import * as jspdf from 'jspdf'; import 'jspdf-autotable'; import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root', }) export class HeroService { constructor() { } generateXml(data,UseType,IsGenerate){ const pdf= new jsPDF(); pdf.autoTable({ html: '#my-table' }) // Or use javascript directly: pdf.autoTable({ head: [['Name', 'Email', 'Country']], body: [ ['David', 'david@example.com', 'Sweden'], ['Castille', 'castille@example.com', 'Spain'], // ... ], }) if (IsGenerate) { pdf.save(data.ReferenceNo + '.pdf'); return ''; } else { return pdf.output('datauristring').replace('data:application/pdf;filename=generated.pdf;base64,', ''); } }

Now Need to Call Service in Your Component:-
 postJson.PdfString = this.pdfService.generatePDF(this.trademodel, true, false);

How to Create xml file and download it or convert into base64 string

 How to Create xml file and download it or convert into base64 string


1).First Install Following packages from Node module
1).npm install xml-writer
page Url:https://www.npmjs.com/package/xml-writer
2).npm install file-saver --save
page Url:https://www.npmjs.com/package/file-saver
Code Writing:-


import * as XMLWriter from 'xml-writer';
import * as FileSaver from 'file-saver';

import { Injectable } from '@angular/core'; @Injectable({
providedIn: 'root', }) export class HeroService { constructor() { }
generateXml(data,type,IsGenerate){

var XMLWriter = require('xml-writer');
xw = new XMLWriter;
xw.startElement('root').writeAttribute('foo', 'value')
.text('Some content');

if (IsGenerate) { const blob = new Blob([this.xw], { type: 'application/xml;charset=UTF-8' }); FileSaver.saveAs(blob, paramData.ReferenceNo + '.xml'); return ''; } else { return this.xw.output; }

}
}
Now Need to Call Service in Your Component:-
postJson.XMLString = btoa(this.dealFastXMLService.generateXml(this.trademodel, true, false));

Asp.net And HTML Css And Web Development: How To Filter and Find any object related to n lev...

Asp.net And HTML Css And Web Development: How To Filter and Find any object related to n lev...:  How To Filter and Find any object related to n level of Child object (like multilevel menu) Example Json: {   "data": [     {    ...

How To Filter and Find any object related to n level of Child object (like multilevel menu)

 How To Filter and Find any object related to n level of Child object (like multilevel menu)



Example Json:

{

  "data": [

    {

      "MenuName": "Dashboard",

      "MenuLink": "/dashboard",

      "MenuParentId": "",

      "MenuIcon": "icon-speedometer",

      "IsChargeableMenu": "false",

      "MenuUUID": "43af0d5a-2989-47d4-98b7-72ff188a64a1",

      "IsInternalMenu": "false",

      "MenuTooltip": "Dashboard"

    },

    {

      "MenuName": "AnalyseFAST",

      "MenuLink": "/graph",

      "MenuParentId": "",

      "MenuIcon": "icon-pie-chart",

      "IsChargeableMenu": "true",

      "MenuUUID": "b1a908fa-6588-4c9b-8131-beda7ab21ae2",

      "IsInternalMenu": "false",

      "MenuTooltip": "AnalyseFAST"

    },

    {

      "MenuName": "General Settings",

      "MenuLink": "/generalsettings",

      "MenuParentId": "",

      "MenuIcon": "icon-menu",

      "IsChargeableMenu": "false",

      "MenuUUID": "a1152c48-9617-4fcf-9df0-b62dc4ee05f4",

      "IsInternalMenu": "false",

      "ChildMenus": [

        {

          "MenuName": "Roles",

          "MenuLink": "/generalsettings/roles",

          "MenuParentId": "a1152c48-9617-4fcf-9df0-b62dc4ee05f4",

          "MenuIcon": "icon-plus",

          "IsChargeableMenu": "false",

          "MenuUUID": "a7b99a52-22c7-4d99-9609-3819bffa4419",

          "IsInternalMenu": "false",

          "ChildMenus": [

            {

              "MenuName": "Create",

              "MenuLink": "/generalsettings/roles/add-roles",

              "MenuParentId": "a7b99a52-22c7-4d99-9609-3819bffa4419",

              "MenuIcon": "icon-arrow-right",

              "IsChargeableMenu": "false",

              "MenuUUID": "5140ce3e-e4c4-4e89-8beb-7f7b86ff124d",

              "IsInternalMenu": "false",

              "MenuTooltip": "Create New Roles"

            },

            {

              "MenuName": "View",

              "MenuLink": "/generalsettings/roles/view-roles",

              "MenuParentId": "a7b99a52-22c7-4d99-9609-3819bffa4419",

              "MenuIcon": "icon-arrow-right",

              "IsChargeableMenu": "false",

              "MenuUUID": "02c04e3e-15e1-4570-b01e-382b3e755813",

              "IsInternalMenu": "false",

              "MenuTooltip": "View Roles"

            }

          ],

          "MenuTooltip": "Roles"

        },

        {

          "MenuName": "Menus",

          "MenuLink": "/generalsettings/menus",

          "MenuParentId": "a1152c48-9617-4fcf-9df0-b62dc4ee05f4",

          "MenuIcon": "icon-plus",

          "IsChargeableMenu": "false",

          "MenuUUID": "884975e8-0ffc-4224-bedf-7c47af0f5d0d",

          "IsInternalMenu": "false",

          "ChildMenus": [

            {

              "MenuName": "Create",

              "MenuLink": "/generalsettings/menus/add-menus",

              "MenuParentId": "884975e8-0ffc-4224-bedf-7c47af0f5d0d",

              "MenuIcon": "icon-arrow-right",

              "IsChargeableMenu": "false",

              "MenuUUID": "7c44b909-fa5b-4a8d-b351-1b1dc3969669",

              "IsInternalMenu": "false",

              "MenuTooltip": "Create Menu"

            },

            {

              "MenuName": "View",

              "MenuLink": "/generalsettings/menus/view-menus",

              "MenuParentId": "884975e8-0ffc-4224-bedf-7c47af0f5d0d",

              "MenuIcon": "icon-arrow-right",

              "IsChargeableMenu": "false",

              "MenuUUID": "5afa0c62-9d86-4a0f-a059-ec73025a2ecf",

              "IsInternalMenu": "false",

              "MenuTooltip": "View Menus"

            }

          ],

          "MenuTooltip": "Menus"

        },

        {

          "MenuName": "Pages",

          "MenuLink": "/generalsettings/pages",

          "MenuParentId": "a1152c48-9617-4fcf-9df0-b62dc4ee05f4",

          "MenuIcon": "icon-plus",

          "IsChargeableMenu": "false",

          "MenuUUID": "f17c9440-6dc0-40d4-88a2-fb18b2fbae43",

          "IsInternalMenu": "false",

          "ChildMenus": [

            {

              "MenuName": "Create",

              "MenuLink": "/generalsettings/pages/add-pages",

              "MenuParentId": "f17c9440-6dc0-40d4-88a2-fb18b2fbae43",

              "MenuIcon": "icon-arrow-right",

              "IsChargeableMenu": "false",

              "MenuUUID": "a5657362-e31c-4059-8bde-bf235883881f",

              "IsInternalMenu": "true",

              "MenuTooltip": "Create Pages"

            },

            {

              "MenuName": "View",

              "MenuLink": "/generalsettings/pages/view-pages",

              "MenuParentId": "f17c9440-6dc0-40d4-88a2-fb18b2fbae43",

              "MenuIcon": "icon-arrow-right",

              "IsChargeableMenu": "false",

              "MenuUUID": "152c1208-5f71-44be-ac4a-b824bf9651dd",

              "IsInternalMenu": "false",

              "MenuTooltip": "View Pages"

            }

          ],

          "MenuTooltip": "Pages"

        }

      ],

      "MenuTooltip": "General Settings"

    }

  ]

}

Now Declaire Variable that store value 

public IsInternalMenu = [];

Now Called api and convert and find data "IsInternalMenu" is "true"

data.forEach(x => {
        this.loadchild(x);
  })

Now write Defination of "loadchild" method

 loadchild(item) {
    if (item.IsInternalMenu == 'true') {
      this.IsInternalMenu.push(item);
    }
    if (item.ChildMenus) {
      item.ChildMenus.forEach(element => {
        if (element.IsInternalMenu == 'true') {
          this.IsInternalMenu.push(element);
        }
        if (element.ChildMenus) {
          this.loadchild(element);
        }
      });
    }
  }

so that's the way (recursive method) that help to find n'th level of child data match
to perticular condition and fetch data and store into seprate variable



Featured Post

how to find n number of nodes have child or cildren

 how to find n number of nodes have child or cildren for that we use recursive function  const   data = {     'id' : '0' ,...

Popular Posts