What is the best way to link the data from the HTML input to the class property in the TypeScript file? (Combining Angular and IntroJs)

I'm working on an onboarding screen with Intro.js and need help with receiving user input. I've been trying different methods like [(ngModel)] = checked, [(checked)] = checked, (checked) = checked, but haven't had any success. Can anyone provide guidance on how to achieve this or confirm if it's possible?

import {Injectable} from '@angular/core';
import * as IntroJs from 'intro.js/intro.js';

@Injectable({
    providedIn: 'root'
})
export class IntrojsService {

    introJs = null;
    checked = false;
    
    constructor() {
    }
    
    welcome() {
        this.introJs = IntroJs();
        this.introJs.start();
        this.introJs.setOptions({
            tooltipClass: 'customTooltip',
            steps: [
                {
                    title: '<img src="../../assets/default-logo.png" alt="logo" class="logo">',
                    intro: '<div class="tooltip-container">\n' +
                        '\n' +
                        '    <div class="tooltip-body">\n' +
                        '        <p>Welcome to the site!</p>\n' +
                        '        <input type="checkbox" ngModel #checked"/>\n' + //input here
                        '    </div>\n' +
                        '</div>\n',
                },
            ],
        }).oncomplete(() => {
            console.log(this.checked);
        }).start();
    }
}

I want the value in the input to be assigned to the "checked" property of the class.

Answer №1

Here is a quick solution that you can try:

this.introJS.onbeforechange((e) => {
const el: HTMLInputElement = (<HTMLInputElement>document.getElementById('mycheckbox'));
  if (el) {
    this.checked = el.checked;
  }
});

this.introJS.setOptions({
  tooltipClass: 'customTooltip',
  steps: [
    {
      title: 'title',
      intro: '<div class="tooltip-container">\n' +
        '\n' +
        '    <div class="tooltip-body">\n' +
        '        <p>Welcome to the site!</p>\n' +
        '        <input type="checkbox" id="mycheckbox" />\n' + //input here
        '    </div>\n' +
        '</div>\n',
    },
    {
      title: 'title1',
    }
  ],
}).oncomplete((v) => {
}).start();

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

Waiting for a function to finish within a nested function in JavaScript

I'm facing a simple issue that I'm struggling to solve. I have two functions and an object in JavaScript (Node.js) structured like this: var auxmap = new Map(); function one() { for(var i...) { //initialize the map and do something tw ...

Obtain the ending section of a URL using JavaScript

Is it possible to extract the username from a URL like this example? I'm interested in seeing a regex method for achieving this. The existing code snippet only retrieves the domain name: var url = $(location).attr('href'); alert(get_doma ...

Implementing position sticky on a div depending on its content text - step by step guide

If the text inside the .newsDate matches the previous or next .newsDate, I want to make its position sticky when scrolling, until it reaches the next .newsMiddleCont div. What I'm trying to achieve: The same date on multiple news items should s ...

Enhance the efficiency of writing the *.d.ts file

I have recently started diving into TypeScript with React and encountered a new concept called a .d.ts file. I am wondering if there is an established best practice for writing this file or if it's more of a developer preference. Can someone verify if ...

Utilizing Mantine dropzone in conjunction with React Hook Form within a Javascript environment

Can Mantine dropzone be used with React hook form in JavaScript? I am currently working on a modal Upload using Tailwind components like this import { useForm } from 'react-hook-form'; import { Group, Text, useMantineTheme } from '@mantine/c ...

What is the best way to access a specific element within a component from a different component?

Seeking assistance with communication issues between React components. I have a Container component containing child components Contact, More, and About for a single-page website. Each child component has a reference set. The problem arises when trying to ...

Troubleshooting dynamic route issues in Angular 6 when making changes in *ngFor

`<div *ngFor="let data of projects"> <a [routerLink]="'/projects/'+data.project_id"> {{data.project_name}}</a> </div>` When I click on the link, the URL changes from http://localhost:4200/projects/1 to http://localhost ...

Tips for merging DTO (Data Transfer Object) with non-DTO objects

I'm currently working on a new endpoint and I need to validate only two parameters (limit and offset) with the dto. The third parameter is not supposed to be checked. My controller test code is not functioning as expected. When I try to use it, the e ...

Steps for aligning the upper rectangular text in the center of the larger rectangular border

https://i.stack.imgur.com/7yr5V.png I was aware of a particular element in html that had text positioned in the upper left corner, but my knowledge didn't go beyond that. Should I be adjusting the translation on both the X and Y axes based on the par ...

What could be causing the issue of why the null check in JavaScript isn't functioning properly

function getProperty(property) { console.log(localStorage[property]) //Displays “null” if(localStorage[property] == null) { console.log('Null check') return false; } return localStorage[property]; } The log outputs "nu ...

Injecting dynamic variables into JSON objects using JavaScript

I am facing a challenge with populating values dynamically from an array of elements. Below is the primary array that I am working with. list = [{name: 'm1'}, {name: 'm2'},{name: 'm3'},{name: 'm4'},{name: 'm5&ap ...

Ways to showcase INPUT TYPE when making a Selection?

I've been struggling with a simple issue and despite trying multiple solutions, I can't seem to get it right. I have a form where I'm using the <select> tag with two options: coo and uh. What I want is for an additional input type fiel ...

What is the reason behind the inconsistent behavior of Javascript's Date.getDate() and .setDate() methods?

As a hobbyist coder, I'm facing a challenging problem with building a dynamic HTML/CSS calendar. My goal is to have cells filled in based on today's date. However, when I attempt to add days to fill in another 13 days by looping through HTML elem ...

Is there a way to transfer JavaScript data to PHP?

<div> <p>This is a sample HTML code with JavaScript for tallying radio button values and passing them to PHP via email.</p> </div> If you need help converting JavaScript data to PHP and sending it via email, there are v ...

Adapting language in real-time: DateTimePicker jQuery Plugin

I am looking to dynamically adjust the language settings of the DateTimePicker jQuery Plug-in (http://xdsoft.net/jqplugins/datetimepicker/) but I keep encountering an "undefined" error for the lang1 variable within the final plug-in function call: <!DO ...

Issue encountered while trying to download Jade through npm (npm install -g jade)

I am having trouble downloading jade via npm on my Mac (Yosemite). After downloading node and updating npm, I tried to install jade but encountered a series of errors that I cannot resolve. Even attempting to use sudo did not help, as it only displayed s ...

Ways to implement distinct values for model and input field in Angular 5

I'm currently working on an Angular 5 application and I have a requirement to format an input field with thousand separators (spaces). However, the model I am using only allows numbers without spaces. Since my application is already fully developed, ...

Tips for fixing the error message of "Cannot access value property of null"

I am facing an issue in my Angular application where I need to conditionally display a div based on certain criteria. Initially, when the page loads, there are no console errors and the div is not shown due to the ngIf condition being false. However, upo ...

Storing form data in a JSON file using JavaScript

For a while now, I've been pondering over this issue. My plan involves creating a desktop application with Electron. As a result, I am working on an app using Node.js and Express.js. The project includes a simple app.js file that executes my website&a ...

Tips for sending data from Jade to a Node.js endpoint function

I am unfamiliar with Express and I am trying to figure out how to pass the user's username from a Jade file to an endpoint function in my JavaScript file. Below is the code for the endpoint function in index.js: router.get('/userdetail', fu ...