Incorporate the Get Your Guide Widget into an Angular2 component

Currently, I am attempting to embed a "Get Your Guide" Widget within an Angular2 application.

Although the script in index.html is being requested successfully, I am facing difficulties adding it to the HTML of the component.

<script async defer src="//widget.getyourguide.com/v2/core.js" onload="GYG.Widget(document.getElementById('gyg-widget'),{'q':'Paris'});"></script>

In my attempts so far:

    <div id="gyg-widget"></div>

And in the typescript file:

import { Component, OnInit } from '@angular/core';

declare var GYG: any;

@Component({
  selector: 'app-excursions',
  templateUrl: './excursions.component.html',
  styleUrls: ['./excursions.component.scss']
})

export class ExcursionsComponent implements OnInit {

  constructor() {}

  ngOnInit() {
    new GYG.Widget(document.getElementById('gyg-widget'),{'q':'Paris'});
  }
}

My current approach appears to be unsuccessful with the following error message:

Error: Error in ./ExcursionsComponent class ExcursionsComponent_Host - inline template:0:0 caused by: GYG is not defined ReferenceError: GYG is not defined at ExcursionsComponent.ngOnInit (excursions.component.ts:20)

At this point, I'm unsure about the correct solution. What steps should I take next?

Answer №1

In my Angular project, I encountered an issue that I was able to resolve by following these steps:

  1. First, I downloaded the Get your Guide library from widget.getyourguide.com/v2/core.js and saved it as lib/gyg.js

  2. Next, I updated my angular-cli.json file with the following lines:

    "scripts": [ "lib/gyg.js" ],

By doing this, I successfully replaced the problematic part mentioned earlier. Although I couldn't directly load the script from an external server as recommended by Get Your Guide.

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

Merging Two Individual Applications into a Single Application Using Angular 8

Recently started learning Angular as a beginner. I am currently working on developing an application and opted to utilize the Angular Multikart ecommerce template. This template comes with separate front-end and admin-end sections, which I can currently ...

What is the best approach for setting a value to an Observable<objectType>?

I'm struggling with this piece of code where I am unable to assign the data. Can someone help me understand why it's not working? Should I consider making the data an Observable? studentObservable<Student>; ngOnInit() { this.id = this.r ...

Having difficulty retrieving a JSON Object value through an angular2 pipe

I am currently working on creating a dynamic table using Angular2. I have set up an Angular2 component with two pipes: the first pipe successfully retrieves the key from the JSON object, which is used as the column for the table. However, the second pipe, ...

Is there a RxJS equivalent of tap that disregards notification type?

Typically, a tap pipe is used for side effects like logging. In this scenario, the goal is simply to set the isLoading property to false. However, it's important that this action occurs regardless of whether the notification type is next or error. Thi ...

Troubleshooting issue: Ineffective transfer of parameters among Angular components

Currently, I am working on an Angular project that consists of two components: property-value and purchase-expenses. Both components are being used within the app.component.html file. My goal is to ensure that if a parameter changes in the property-value c ...

Implementing the 'colSpan' attribute in ReactJS

I encountered an error saying "Type string is not assignable to type number" when attempting to include the colSpan="2" attribute in the ReactJS TypeScript code provided below. Any suggestions on how to resolve this issue? class ProductCategoryRow exten ...

Angular fails to combine values within routerLink

The issue is straightforward - I have a component that retrieves the last searched items saved in sessionStorage as an array of ListItem objects: export class SearchlistComponent { results = JSON.parse(<string>sessionStorage.getItem("lastSear ...

Conquering the need for a 426 upgrade was a challenging task

For the past few months, I have been diligently working on a web application with Angular for the front end and Node/Express/Mongo for the backend. My setup involves running Angular on localhost:4200 and Node on localhost:3000. However, some members of ou ...

Is there a way to develop a unique Angular directive that can toggle the visibility of a child element when a neighboring element is clicked?

Is there a way to create a unique Angular directive that can reveal and conceal a child element when a neighboring element is clicked? I would like the ability to display "custom_elem" using custom directives when the h2 element is clicked. It's imp ...

Angular validation with input binding using if statement

I have developed a reusable component for input fields where I included a Boolean variable called "IsValid" in my typescript file to handle validation messages. Here is the code from my typescript file: export class InputControlsComponent implements OnIn ...

Angular firing off select option with object properties

Within my Angular application, I am faced with a situation involving a <select> element that contains a list of <option> elements whose values are associated with objects. My goal is to capture the last selected value using the following code: ...

Tips for integrating angular signature functionality using fabricjs in the latest version of Angular (Angular 11)

After struggling to make paperjs and the angular-signature library work together, I was at my wit's end. But then, I stumbled upon a different solution that proved to be much better. I realized that posting the solution under the appropriate question ...

What is the reason that specifying the type of function parameters does not result in conversion being

Seeking clarity here. I have a TypeScript function (using version 1.7) that is linked to the change event of a select dropdown in HTML: toggleWorker(stsID: number): void { // get status object by selected status ID let cStatus: Status = this.s ...

Oops! It seems like there has been an issue. The EnjoyHint is not

Encountered the following error message: https://i.stack.imgur.com/JL4l6.png The error in my code is within the line that initializes a new EnjoyHint object. Seeking assistance to resolve this issue. public initiate(stepName) { const steps = ...

Learn how to effortlessly move a file into a drag-and-drop area on a web page with Playwright

I am currently working with a drag-zone input element to upload files, and I am seeking a way to replicate this action using Playwright and TypeScript. I have the requirement to upload a variety of file types including txt, json, png. https://i.stack.img ...

Implementing a Set polyfill in webpack fails to address the issues

Encountering "Can't find variable: Set" errors in older browsers during production. Assumed it's due to Typescript and Webpack leveraging es6 features aggressively. Shouldn't be a problem since I've successfully polyfilled Object.assign ...

Having trouble accessing child directives in Angular 2 using @ContentChildren

I'm facing an issue getting nested directives from a parent directive, as @ContentChildren is not being populated. The main goal is to implement lazy-loading for images, where each image is a nested directive within the parent directive. For instan ...

Is it possible that the installation issue with 'File' from ionic-native is due to dependencies?

As a newcomer to Ionic2, I'm facing some beginner obstacles. Despite my extensive search efforts, I haven't been able to find any examples related to my issue. My current goal is to write a file to a specific directory on the device using Ionic2 ...

Issue with setting {responseType: 'text'} in Angular7

Situation: When an API call is made from Angular7, Node (via express) is called to return chunked data of type string - the goal is to capture this string data and display it as a string On the Server-side: The data sent from the Node backend is in &apos ...

Controller in Angular checks for element overflow

In a grid, there are fields that may contain an Ellipsis when the content is too large. In such cases, a tooltip should display the full content. I have written a method in the component code to determine if an element has an ellipsis or not. However, whe ...