0

I have been stuck for almost a week. Want to fetch URL parameters and send it to backend(Mongodb). Please help me. Every suggestions will be appreciated.

I am able to get URL params into HTML but want to show it in MongoDatabase. Sharing my code below

Contact.component.ts

import { Component, OnInit, NgModule, SimpleChanges, OnChanges, DoCheck, Input } from '@angular/core';
import { Feedback } from '../model/feedback';
import { AuthGuardService } from '../guards/auth-guard.service';
import { ActivatedRoute } from '@angular/router';
import { ApiService } from '../api.service';


@Component({
  selector: 'app-contact',
  templateUrl: './contact.component.html',
  styleUrls: ['./contact.component.scss', './contact.component.mobile.scss']
})
export class ContactComponent implements OnInit {
  //name of parameters to fetch
  // @Input() authors: AuthorModel;
  bannerid: string;
  devicetype: string;
  country: string;

  constructor(private authGuardService: AuthGuardService,
    private route: ActivatedRoute,
    private apiService: ApiService) { }


  ngOnInit(): void {
    this.route.queryParams.subscribe(queryParam => {
      this.bannerid = queryParam.bannerid;
      this.devicetype = queryParam.devicetype;
      this.country = queryParam.country;
      console.log(queryParam);
    })
  }

  ngOnChanges(changes: SimpleChanges): void {
    console.log(changes);
  }

  feedModel = new Feedback('', '', '', '', '', '', '');


  onSubmit(data): void {
    // console.log(data);
    //  console.log(this.feedModel);
    this.apiService.onSubmit(data);
    this.authGuardService.feedBack(this.feedModel);
  }
  // queryParam(latest): void{
  //   console.log(latest);
  //   this.apiService.queryParam(this.bannerid);
  // }


}

6
  • Like you want to get content from get url params, then fetch into a rest api to connect with mongodb ? Commented Mar 14, 2023 at 14:30
  • He Elikill, I just want to show angular app URL params in mongodb (using node.js). Example url: localhost:4201/… Commented Mar 14, 2023 at 14:40
  • 1
    and where are you stuck ? You seems to well get params. And now you don't know what to do ? If yes, it's offtopic on stack overflow as it's too board. You should check for Rest API to be able to connect with your DB, and use http request to call it Commented Mar 14, 2023 at 14:48
  • Hi Elikill, Yes i am able to fetch params. It is just that i want to send it to mongodb. Commented Mar 14, 2023 at 15:03
  • @Sam you're going to have to do that on the server-side. Commented Mar 14, 2023 at 15:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.