Error Alert: The function split cannot be applied to params[item]

ERROR! The console is outputting a message stating that TypeError: params[item].split is not a function. I would greatly appreciate any assistance in resolving this issue. Understanding where I went wrong in tackling this problem would be the most beneficial help.

routeReady() {
    this.activeRoute.queryParams
        .pipe(switchMap(params => {
            if (!params['filter']) {
                // using previous month as default
                let date : Date = new Date();
                date.setDate(1);
                date.setMonth(date.getMonth() - 1);
                this.formData.startDate = DateUtils.dateToText(date);
                date.setDate(DateUtils.getDaysInMonth(date));
                this.formData.endDate = DateUtils.dateToText(date);
            }
            ['startDate', 'endDate', 'club'
                , 'subscription', 'sold'].forEach(item => {
                if (item in params && params[item] !== '') {
                    this.formData[item] = params[item];
                }
            });
            ['courts', 'groups', 'zones'].forEach(item => {
                if (item in params && params[item] !== '') {
                    this.formData[item] = params[item].split(',');
                }
            });
            return Promise.resolve(true);
        }))
        .subscribe();
}

This error has me stumped:

https://i.sstatic.net/poejp.png

Answer №1

It's not a standard object, but rather some kind of special angular feature. To access its value, you need to use:

params.get('specific property');

In your scenario, the code would look like this:

params.get(item).split(',');

If I were in your shoes, here is how I would handle it:

['courts', 'groups', 'zones'].forEach(item => {
  const value = params.get(item);

  if (value) {
    this.formData[item] = value.split(',');
  }
});

Answer №2

This particular code assumes that the variable params[item] is of type string:

this.formData[item] = params[item].split(',')

Remember, JavaScript strings offer a split method for manipulation:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split

If the data stored in params[item] is not text, then it will not have a split method and an error will occur:

params[item].split is not a function

To verify the data type, you can use:

console.log('params[item]', params[item], typeof params[item])

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue encountered while validating password using regex pattern?

There seems to be an issue with password validation when requiring 1 upper case, 1 lower case, 1 number, and 1 special character. methods: { validateBeforeSubmit() { this.$validator.localize('en', dict) this.$validator.validate ...

Stop the interval when the variable equals "x"

I've created a function that controls a specific row in my database using AJAX. The function is triggered by a click event and placed within a setInterval function to check ten times per second. Initially, it will return 0, but eventually (usually wi ...

wordpress widget that triggers a function when a click event occurs on jquery

I'm facing an issue where this function works perfectly in my header, but seems to have no effect when used in a widget $("#myID").click(function(){ var name = $("#name").val(); var phone = $("#phone").val(); console.log(name +" "+ phone) ...

Activate OnChanges by modifying a property within the object that is bound to the data

Is there a way to make ngOnChanges() fire when a property of a data-bound object changes without needing to assign a new object to the property? // Inside the component @Input() myObj: ObjType; // Component code... The above scenario does not trigger the ...

establish the parent child size with CSS

In my current project, I am faced with a challenge regarding the CSS and HTML code. I am attempting to have a <div> element positioned after an <img> element inherit the width and height of the image. This <div> is meant to act as an over ...

Create a compressed package of a Vue project that can easily be inserted into a Blogger blog post as a single HTML file

Is there a way to package all the files related to a Vue.js project (HTML, JavaScript, CSS) into one single HTML file for easy deployment on a Blogger Blogspot post? In the past, a question similar to this was asked regarding bundling files into a single ...

Records of docker-related errors detected in the logs

I am looking to release the Angular application with GitLab CI/CD pipeline on Azure. I have set up the GitLab pipeline as shown below: Upon deployment, I encountered errors in the logs which are displayed below: Seeking assistance to resolve this issue ...

Unexpected error encountered in Angular 2 beta: IE 10 displays 'Potentially unhandled rejection [3] SyntaxError: Expected'

Question regarding Angular 2 Beta: I am starting off with a general overview in the hopes that this issue is already recognized, and I simply overlooked something during my research. Initially, when Angular 2 Beta.0 was released, I managed to run a basic m ...

Creating subclass mappings and defining subclasses dynamically using Typescript at runtime

I am puzzled by the structure of 3 classes: A, B, and C. Both B and C extend the abstract class A. abstract class A { public name: string; constructor(name: string) { this.name = name; } abstract getName(): string; } class B extends A { g ...

Dynamic backdrop featuring engaging content

I am currently working on a WordPress website that features a dynamic background. While I have successfully implemented movement to the background, the content on the site remains static and unaffected by scrolling. The background does not move alongside t ...

There was an issue encountered while trying to install Electron using the command 'npm install electron'

While attempting to install electron using npm install electron, I encountered the following error: 908 error code 1 909 error path C:\Users\name\Documents\name\Code\code\node_modules\gl 910 error command failed ... ...

Utilizing Vuex Store in Blade Template | Laravel and Vue.js

I'm trying to figure out how to access a method or variable that is defined in the Vuex 4 store within my Blade file. Currently, I am utilizing a compiled app.js from Vite. While I can easily access the store in Vue.js components, I am curious if it&a ...

Revamp the Twitter button parameters or alter its settings

I'm working on a web page that includes a Twitter button. Before the button, there is an input field and a form where users can easily add relevant hashtags for the page. The goal is to take the text from the input field and populate it in the Twitter ...

The AJAX functionality for POST, PUT, and DELETE requests is functioning properly, however, the GET request is experiencing CORS

I've been delving into Java, Spring, PHPmyadmin, and a combination of pure HTML and JS for my first API project. I've managed to successfully implement POST, PUT, and DELETE requests, but I'm encountering an issue with GET requests by ID usi ...

Troubleshooting issues with the 'date' input type feature on mobile devices

When I use the following code: <input type='month' ng-readonly='vm.isReadonly' required min="{{vm.threeMonthsAgo}}" max='{{vm.oneMonthAhead}}'/> I am experiencing some difficulties on mobile devices that do not occur o ...

Encountering an error with the node module timestampnotes: 'command not recognized'

I am encountering an issue while trying to utilize a npm package called timestamp notes. After executing the following commands: $npm install timestampnotes $timestamp I receive the error message: timestamp:126: command not found: slk Subsequently, I ...

AJAX using PHP returns an object containing null values

As a beginner in ajax programming, I encountered a small issue. I created a function in jQuery that makes an ajax call to a PHP file, which then retrieves information about a player from the database. However, when the PHP file responds to the ajax functio ...

Observable doesn't respond to lazy loaded module subscriptions

I am trying to understand why my lazy loaded module, which loads the test component, does not allow the test component to subscribe to an observable injected by a test service. index.ts export { TestComponent } from './test.component'; export { ...

Performing simultaneous document queries within a single API in MongoDB

I am currently working with an API written in typescript and attempting to execute parallel queries for the same document by using Promise.allSettled. However, I have noticed that it is performing poorly and seems to be running sequentially instead of in p ...

How can jQuery Sortable Connect Lists help store values within list items?

Currently, I am exploring the demonstration for sorting items at this link. However, I am facing a challenge where I want the text in the list to appear a certain way, but when I save the data on the server side, I need to use values instead. Since the < ...