Encountering an issue when trying to pass a variable using a constructor

Whenever I run my TypeScript file in Angular, I encounter an error in the console.

Error: compiler.js:215 Uncaught Error: Can't resolve all parameters for SearchNameComponent: ([object Object], ?).

Below is my complete code:

import { Component, OnInit } from '@angular/core';
import {StudentSearchService , Students} from '../service/student-search.service';
import DataSource from 'devextreme/data/data_source';


@Component({
  selector: 'app-search-name',
  templateUrl: './search-name.component.html',
  styleUrls: ['./search-name.component.css'],
  providers: [StudentSearchService],
})
export class SearchNameComponent implements OnInit {

  std: Students[];
  data: any = '';
  constructor(public students: StudentSearchService, data: any) {

    this.std = students.getstudent();
    console.log(data);
}

  ngOnInit() {
  }

}

Answer №1

An error occurs in this code snippet due to a mismatch between the constructor definition and the number of arguments being passed.

To resolve this issue, you can either make the second argument optional or remove it from the constructor altogether.

Here is an example that illustrates the problem:

export class SearchNameComponent implements OnInit {

  std: Students[];
  data: any = '';
  constructor( public students: StudentSearchService) {

    this.std = students.getstudent();
    console.log(data);
}

  ngOnInit() {
  }

}

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

Discover a technique to display every individual "echo" statement from PHP in sequence, rather than waiting for the entire script to finish executing

I have developed a PHP script that takes some time to execute and displays multiple "echo" statements as the progress is being made. The script connects to an FTP server, deletes all contents, and then uploads new files. Everything is functioning correctly ...

Issue with Styling/Accordion in Angular 11 Bootstrap 4.6.0 - unable to display properly

Currently, I am in the process of relearning some Angular basics. However, I am facing difficulties with a fundamental element of Bootstrap - the Accordion. I seem to be unable to style it or make it work properly. It seems like I might have overlooked som ...

An error is triggered when an HttpClient post does not return any data

While sending a post request from my angular application to a web api, I am encountering an issue. The response from the api is supposed to be either a 200 status or a 404 status without any data being returned. An example of some headers for the 200 respo ...

A sleek CSS text link for a stylish video carousel

I am attempting to create a CSS-only text link to video slider within our Umbraco CMS. Due to the limitations of TinyMCE WYSIWYG, I am restricted in the amount of code I can use as it will strip out most of it. So far, I have developed a basic CSS slider ...

Transform a Django/Python dictionary into a JavaScript dictionary using JSON

I need to convert a Python dictionary into a JavaScript dictionary. From what I understand, I have to first convert the Python dict into JSON format and then transform it into a JavaScript Object. view.py jsonheaderdict = json.dumps(headerdict) {{jsonhe ...

How can I stop the counter from running when the modal is hidden?

I am looking to increment a counter only when a modal is being displayed. However, I am facing an issue where the counter continues to increase even after the modal has been closed. Can someone provide insights on what might be wrong with my code snippet ...

Angular 5 Pipe fails to run in certain scenarios

I am new to Angular and I have created a custom pipe called "arrayToString" as shown below: import { Pipe, PipeTransform } from '@angular/core'; import * as _ from 'lodash'; @Pipe({ name: 'arrayToString' }) export class Arra ...

Store the current function in the cache, incorporate new features, and execute those additions upon calling another function

I have a pre-existing function that I am unable to directly access or modify. Due to this limitation, I have resorted to caching the function and incorporating additional functions alongside it. This function loads periodically, sometimes occurring on pag ...

Access the serialized form data fields using Express.js

I'm currently facing difficulty in accessing specific fields of my serialized formdata within my express router. Here is the ajax request I am using: var formData = $("#add-fut-account-form").find("select, textarea, input").serialize(); $.ajax({ u ...

What is the mechanism by which a custom hook, functioning as a trigger, initiates the re-rendering of a separate function component?

According to the official documentation on Custom React Hooks, one particular use case for utilizing a custom hook is demonstrated through the following example: function FriendListItem(props) { const isOnline = useFriendStatus(props.friend.id); retur ...

Clicking on AngularJS ng-click to navigate to a different page within an Ionic framework application

My goal is to navigate to another page when clicking on a button in the Ionic navbar at the top. However, I am encountering an issue where upon clicking, all nav bar buttons disappear. Interestingly, using dummy codes triggers an alert successfully. But w ...

Tips for accepting numerous images in a Angular 4 application through Web Api

As a newcomer to Angular 4 and Web API, I am currently working on uploading multiple images from an Angular 4 application to the Web API. While I have successfully received the images in the API and can see the count of uploaded images during debugging, I ...

Calculate the unique UV coordinates for a custom Buffer Geometry in THREE.JS

I am currently working on creating a curved wall using a vertices array in three JS. The array contains some base vertices in 2D which represent the bottom vertices of the wall. These vertices include the center, lower, and upper points, making it a two-fa ...

Creating a simulated loading screen

I have created a preloader page for my website following tutorials, such as the one found here: https://codepen.io/bommell/pen/OPaMmj. However, I am facing a challenge in making this preloader appear fake without using heavy content like images or videos. ...

What is the standard way to write the server-side code for HTTP request and response handling?

I stumbled upon these resources: How to send HTTP request GET/POST in Java and How to SEND HTTP request in JAVA While I understand the client-side aspect, how can this implementation be done on the server side? The goal is to utilize the link on the clie ...

How to integrate custom plugins like Appsee or UXCAM into your Ionic 2 application

Struggling to integrate either Appsee or UXcam into my project. I attempted to import the plugin like this, but it didn't work: // import { Appsee } from '@ionic-native/appsee'; I read somewhere that you need to declare the variable for Ty ...

Exploration of frontend utilization of web API resources

I've come across this issue multiple times. Whenever I modify a resource's result or parameters and search for where it's utilized, I always end up overlooking some hidden part of the application. Do you have any effective techniques to loc ...

Adjust the size of the image within a designated container to decrease its proportions when there is an excess of text present

I am working on a project where I need to resize an image based on the available space within its container. When there is text in the description, the image should adjust its size accordingly without pushing the text upwards. I am using React for this pro ...

Component not being returned by function following form submission in React

After spending a few weeks diving into React, I decided to create a react app that presents a form. The goal is for the user to input information and generate a madlib sentence upon submission. However, I am facing an issue where the GenerateMadlib compone ...

Tips for displaying an item from an array within a separate component using React

When it comes to rendering a single post from an array of posts passed to one component into another component, I'm encountering some difficulties finding the right approach. My setup includes two components: the first one, "Blog," displays previews ...