Angular 13 Not Seeing Custom Pipes

i am porting over and angular 6 app to angular 13 and i am having trouble with pipes. the app wont compile.

i have a custom pipe on a component that the compiler says doesnt exist
Property ‘shortDate’ does not exist on type ‘TransactionsComponent’.

code is as follows (and works in old version of angular)

angular pipe:

import { PipeTransform, Pipe } from '@angular/core';
import { DatePipe } from '@angular/common';
    
    @Pipe({
        name: 'shortDate' 
    })
    export class DateFormatPipe extends DatePipe implements PipeTransform {
        override transform(value: any, args?: any): any {
            ///MMM/dd/yyyy 
            return super.transform(value, "MM/dd/yyyy");
        }
    }

html

<div class="dt">{{transaction.transactionDate | date: shortDate}}</div>

Shared Module

    @NgModule({
  declarations: [  
    DateFormatPipe 
  ],
  imports: [ 
    AppRoutingModule,
    BrowserModule,  
    FormsModule,
    HttpClientModule,
    HttpInterceptorModule,  
    ReactiveFormsModule, 
   
  ],
  exports: [ 
    AppRoutingModule,
    BrowserModule,  
    FormsModule,
    HttpClientModule,
    HttpInterceptorModule,  
    ReactiveFormsModule ,
   
  ],   
})
export class SharedModule {
    static forRoot(): ModuleWithProviders<SharedModule> {
      return {
        ngModule: SharedModule,
        providers: 
        [   
            DateFormatPipe,  
        ]
      };
    }
  } 

consuming module

    @NgModule({
      declarations: [ 
      ],
      imports: [ 
       SharedModule  
      ],
      providers: [  
      ], 
    })
export class TransactionModule{ }

in app.module

     imports: [ 
    SharedModule.forRoot(),
    TransactionModule
  ] ,

please note: I have also tried to put the pipe in the exports section of shared module. that doesnt work either. i’m sure im just missing something silly. does anyone have any ideas?

I have this error in building react app in server console “Uncaught ReferenceError: Cannot access ‘__WEBPACK_DEFAULT_EXPORT__’ before initialization”

Row.js:18

   Uncaught ReferenceError: Cannot access '__WEBPACK_DEFAULT_EXPORT__' before initialization
at Module.default (Row.js:18:1)
at ./src/axios.js (axios.js:2:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/Banner.js (App.js:20:1)
at options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:62:1)
at ./src/App.js (bundle.js:18:65

How do i remove this error whenever i use fetchUrl, useState and useEffect in row.js file it shows this error.

Converting SVG image to PNG canvas using Javascript

I am trying to convert an SVG into a PNG via Javascript using a Canvas object

  svgString2Image(svgString, width, height, format, callback) {
    console.log(width);
    console.log(height);
    var format = format ? format : 'png';

    // Convert SVG string to data URL
    let imgsrc = 'data:image/svg+xml;base64,' + btoa(unescape(encodeURIComponent(svgString)));
    console.log(imgsrc); // This image is OK and displays in the browser correctly

    let canvas = document.createElement("canvas");
    canvas.width = width
    canvas.height = height;

    let context = canvas.getContext("2d");
    // context.fillStyle = "white";
    // context.fillRect(0, 0, canvas.width, canvas.height)

    let image = new Image();
    image.src = imgsrc;

    image.onload = function () {
      context.clearRect(0, 0, width, height);
      context.drawImage(image, 0, 0, width, height);

      canvas.toBlob(function (blob) {
        let filesize = Math.round(blob.size / 1024) + ' KB';
        if (callback) callback(blob, filesize);
      });

    };

  }

The encoded data URL is OK afaik. I can open it directly in a browser. However depending on how the SVG is displayed in the application. Sometimes part of the image appears on the canvas and sometimes it does not or it gets cut.

The calling function looks like this:

  exportTree() {
    console.log("exporting file");

    let left = this.root;
    let right = this.root;
    this.root.eachBefore((n: any) => {
      if (n.x < left.x) { left = n; }
      if (n.x > right.x) { right = n; }
    });

    let svg = d3.select("svg")
    let svgString = this.getSVGString(svg.node());

    const height = right.x - left.x + this.margin.top + this.margin.bottom;
    console.log(height);

    // passes Blob and filesize String to the callback
    this.svgString2Image(svgString, this.width, height, 'png', save);

    function save(dataBlob, filesize) {
      saveAs(dataBlob, 'tree_hierachy.png'); // FileSaver.js function
    }

  }

The width is fixed to 800 and the height is calculated based on the number of nodes being shown in a kind of tree hierarchy.

Imagine the method can be called with width 800 and height 290. For example in this case the image is cropped:

enter image description here

I tried also to use getBBox().width and getBBox().height but the behaviour seems to be the same.

Any help appreciated.
Thanks

How to create a conditional test?

Good day everyone! I’m trying to create a conditional test in cypress but can’t figure out how to do it. I have a construct that must be executed if there is an element in the DOM. If it is not, then there should be just a pass. How to implement it?

it("something test", () => {
    cy.get("body").then(($body) => {
      if ($body.find('button[name="button-row-add"]')) {
        cy.get('button[name="button-row-add"]').click();
        cy.get('input[name="newValue"]').type("Cypress Test String");
        cy.get('button[name="submit-dimension"]').click();
        cy.wait(500);
      }
    });

    cy.get(".table-cell").each(($el) => {
      cy.wrap($el).dblclick();
      cy.wrap("[class^=form-cell]").as("form").should("exist");
      cy.wrap("@form").get('textarea[name="value"]').type("Cypress Sell Test");
      cy.wrap("@form").get('button[aria-label="submit-button"]').click();
    });
  })

How do I get a style property value from an SVG element that is animated using transform?

If I have an SVG element that is animated using transform, either using SMIL or CSS, how do I get the computed style of the property that is animated?

Here I have a <rect> that rotates, but as you can see the rotate property just returns none:

var rect1 = document.getElementById('rect1');

setTimeout(function(){
  let rectStyle = getComputedStyle(rect1);
  console.log(rectStyle.rotate);
}, 200);
<svg id="svg" width="200" viewBox="0 0 4 4" xmlns="http://www.w3.org/2000/svg">
  <rect id="rect1" x="1" y="1" width="2" height="2" fill="red">
    <animateTransform attributeName="transform"
      attributeType="XML" type="rotate"
      values="0 2 2; 360 2 2" dur="10s"
      repeatCount="indefinite"/>
  </rect>
</svg>
var rect1 = document.getElementById('rect1');

setTimeout(function(){
  let rectStyle = getComputedStyle(rect1);
  console.log(rectStyle.rotate);
}, 200);
#rect1 {
  transform-origin: center;
  animation-name: rotate;
  animation-duration: 10s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
<svg id="svg" width="200" viewBox="0 0 4 4" xmlns="http://www.w3.org/2000/svg">
  <rect id="rect1" x="1" y="1" width="2" height="2" fill="red" />
</svg>

Can’t deep copy an observable array in knockoutJS

I have an array with objects having observable and non-observable properties in my knockout JS project which I want to copy so I can have a temporary array that can replace the original one after confirmation. Before the comfirmation, I recalculate one of the observable values of the objects in the array, but without confirmation, I don’t want to edit the original array, which sadly happens. I tried several methods to deep copy the array (.slice(0), simply tempArray(array), tempArray(ko.observable(array()), even with jQuery $.extend() and ko.mapping.fromJS etc.), but none of them works for me. The ko.mapping.fromJS changed all of my non-observable properties to observables, in all the other cases, i could not get rid of the binding and the original array was changed as well.

So, what is the best way to deep copy a knockoutJS array without changing the contained objects’ properties from observable to non-observable or vice versa (and of course without editing the original array)?

How to make page transitions with a link?

There are cards on the homepage where I list the policies. Above these cards is a button called “details”. I want to go to the detail of the product when I press this button. But a product can only have one type. For example,

if it is a vehicle policy, the link should be: /policies/vehicle/detail

if it is a housing policy, the link should be: /policies/housing/detail

More than one product can be displayed on the Home Page.

<Link to={{ pathname: history.location.pathname + activePolicies.policyGroup + '/details', state: { policy: activePolicy } }}>
  {t('general.details')}
  <AS.KeyboardArrowRightIcon />
</Link>

Since activePolicies is an array, I cannot place it as **activePolicies.policyGroup.

How can I solve the problem?

Processing the data into a desired format in javaScript

I am new to javaScript and want to process the following array –

var a=[
 "John-100",
 "Mark-120",
 "John-50",
 "Mark-130"
]

into the following format –

a = {
    "John": [100, 50],
    "Mark": [120, 130]
}

but have been unable to do so.
Any help will be very much appreciated. TIA!

Edit – Any other format ideas where the marks of a particular student can be grouped togethe are also welcome.

Got error `NetworkError when attempting to fetch resource` when fetching json file

I know this question is already there in stack overflow, but it’s not relevant for my issue. I didn’t get a solution.

I have two file index.html and data.json.

My code:

<!doctype html>
<html>
    <head>
    </head>
    <body>
        <script>
            async function fun(){
                const res = await fetch('temp.json');
                const dat = await res.json();
                return      (Object.values(data));
            }
            console.log(fun());
        </script>
    </body>
</html>
{
"1": "One",
"2": "two",
"3": "Three"
}

I got the error mentioned in the title in my browser (firefox and mobile chrome).
Console:

Promise { <state>: "rejected", <reason>: TypeError }
<state>: "rejected"
<reason>: TypeError: NetworkError when attempting to fetch resource.
<prototype>: Promise.prototype { … }

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///home/kashyap/Desktop/data.json. (Reason: CORS request not http).

how to solve the gitbash clone fatal error

I’m a beginner to GitHub.I need to clone the https://github.com/UFPA/abc.git . when i typed the code
git clone https://github.com/UFPA/ufpa.git
It gives me the error

Cloning into ‘ufpa’…
fatal: unable to access ‘http://github.com/UFPA/ufpa.git/’: Failed to connect to 172.22.254.57 port 1080 after 2071 ms: Connection refused

It will be firewall issue? because my system port is 8080 and the error show the port 1080.

CSS and JS of Bootstrap Toggle are not working after UpdatePanel was triggered in Asp.Net

Do you have any ideas on how the JS and CSS of Bootstrap toggle (www.bootstraptoggle.com) will work after an UpdatePanel trigger in ASP.net?

I tried Sys.WebForms.PageRequestManager.getInstance() and pageLoad but it did not load.
Please see the images:

**Initial Load: https://i.stack.imgur.com/WG6At.png

**After UpdatePanel trigger: https://i.stack.imgur.com/Ib1G1.png

How to use setSelection to skip newlines?

So I am making an auto-complete feature for text in a quill editor for Angular, where I have to manually place the cursor because I could not find a workaround to the cursor going by itself to the beginning of the text-editor.

But I am running into a problem where I don’t know how to account for
in my htmlstring from the quill editor in deciding where to place the cursor. The setSelection takes a number corresponding to the number of characters and guestimating the number of characters
has does not seem to work.

Ajax call in external JavaScript file is not working in Struts2

I am developing Struts2 web application. There is a common value (ex. URL) that used in several JSP pages and I get those values to a external JavaScript file as below.

a.js

var test;
function init() {
  
    $.ajax({
       url: "getStringData.action",
       type: 'GET',
       async : true,
       success: function(response) {
            test = response;
            alert(response);
        }
    });
}

init();

This is my jsp page.

b.jsp

  <script type="text/javascript" src="a.js"></script>

  var value = test;

test is the value that get from imported a.js file.

Struts.xml

<action name="getStringData" class="com.projectName.action.SampleAction" method="getStringData">
<result>/b.jsp</result>
<result name="error">/error.jsp</result>

SampleAction.java

public String getStringData(){
  String dataValue = "sample string value";
  return dataValue;
} 

Ajax function is not working. How can I fix it.

Angular: regex for mapped emojis to replace all of them at once for given string

I have a string that may look like this:
“Something something 😛 something 😀 something :] etc..”
And I want to replace all of emojis “keys” with emojis from node-emoji library.

So I have a map with all wanted emojis:

export const emojisAliases = {
  slightly_smiling_face: [':)', ':-)'],
  upside_down: ['(:', '(-:'],
  disappointed: [':(', ':-(', ':<', ':-<'],
  laughing: ['xD', 'xd', 'XD'],
  stuck_out_tongue_winking_eye: [';p', ';P'],
  stuck_out_tongue: [':p', ':P'],
  grin: [':d', ':D'],
  hushed: [':o'],
  scream: [':O'],
  wink: [';)', ';-)'],
  sunglasses: ['B|'],
  nerd_face: ['B-)', 'B)'],
  angry: ['>:('],
  confused: [';/'],
  cry: [";'(", ":'("],
  smiling_imp: ['3:)', '3;)'],
  innocent: ['o:)', 'O:)', 'o;)', 'O;)'],
  kissing_closed_eyes: [':*', ';*'],
  heart: ['<3'],
  blush: ['^_^', ':$'],
  expressionless: ['-_-'],
  neutral_face: [':|'],
  flushed: ['o.o', 'O.O'],
  thumbsup: ['(y)'],
  thumbsdown: ['(n)'],
  sweat: ['(:|'],
  rage: [':@', ';@'],
  worried: [':S', ':s', ';S', ';s'],
  face_vomiting: [':&', ';&', ':-&', ';-&'],
  'star-struck': ['*.*'],
  thinking_face: [':-?', ':?'],
  pray: ['_/\_'],
  moneybag: ['($)', '$$']
};

So I wanted to create a function that replace them but I dont have any idea how to do this, I thought about regex but I’m not sure if it’s a right solution in this case.

I also could iterate over all string characters and take two characters that are next to each other and check if they match to one of aliases.. but I’m not sure about that.

Maybe someone can help me with that?