Deploy the Angular standalone component numerous times across a single page using Bootstrap

Edit

After receiving input from Andrew, I have decided to adjust my strategy:

  • Replacing survey-angular with the survey-angular-ui package
  • Implementing a widget approach similar to the one outlined in this example
  • Developing a single module that encompasses all components and registers them with the Serializer:
import { NgModule } from '@angular/core';
import { ColorPickerModule } from 'ngx-color-picker';
import { ColorPickerComponent } from './color.component';
import { registerColorPicker } from './color.model';

// Register all components here
registerColorPicker();

@NgModule({
  // Declare all Angular components
  declarations: [ColorPickerComponent],
  // Import any library modules you need for your custom widgets
  imports: [ColorPickerModule],
})
export class CustomWidgetsModule {}
  • Next, import this CustomWidgetsModule into your main app module

I have retained the original question title and content below for future reference.


I am exploring the use of standalone Angular components as a foundation for developing advanced widgets to serve as custom questions for SurveyJS.

My initial method involves generating an NgModule dynamically, configuring it with necessary imports, and then bootstrapping it to the HTML element of the custom question:

afterRender: async (question: Question, el: HTMLDivElement) => {
  @NgModule({
    imports: [BrowserModule, HttpClientModule, ...],
    providers: [...],
  })
  class CustomQuestionModule implements DoBootstrap {
    ngDoBootstrap(appRef: ApplicationRef): void {
      appRef.bootstrap(widgetComponentClass, el);
    }
  }

  await platformBrowserDynamic().bootstrapModule(CustomQuestionModule);
}

With the introduction of standalone components in Angular 14, I anticipated being able to eliminate the generated NgModule and utilize the bootstrapApplication API for component bootstrapping.

This works effectively for a singular component. However, when attempting to bootstrap multiple identical standalone components, they all attach to the HTML element of the initial component. In essence: I am struggling to bootstrap two identical standalone components to separate HTML elements?

With the previous method (as depicted in the code snippet above), I could specify the target element for module bootstrapping. Is there a comparable feature available using standalone components?

Answer №1

I recommend avoiding the use of afterRender.

We have recently implemented Angular rendering for SurveyJS survey-form runner and Creator. It is advised to uninstall the "survey-angular" package and switch to using "survey-angular-ui" instead. The former is a wrapper for knockout JS, while the latter utilizes platform independent "survey-core". Further details can be found here.

You have the option to customize our rendering by creating an Angular component. Check out this example on altering choice item rendering in a dropdown question. Our goal is to transform SurveyJS libraries into a Lego constructor, enabling customization through custom components in either Angular or React depending on the platform.

Regards,

Andrew, SurveyJS Team

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

Typescript error: The property 'set' is not found on type '{}'

Below is the code snippet from my store.tsx file: let store = {}; const globalStore = {}; globalStore.set = (key: string, value: string) => { store = { ...store, [key]: value }; } globalStore.get = (key) => { return store[key]; } export d ...

Modify the dropdown menu title dynamically based on the selection made in Angular

My Angular web-application has a dropdown menu that looks like this: <div class="btn-group" dropdown> <button dropdownToggle type="button" class="btn btn-primary dropdown-toggle">NAMEOFDROPDOWN <span class="caret"></span>&l ...

The function is not defined for this.X in TypeScript

I am currently developing an application using Angular 6. Within my app, I have the following code snippet: import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Component({ selector: ...

Oops! There seems to be an issue with Angular - I'm getting an

I need to retrieve JSON data from the server and only display it on the web page after clicking a button. However, I encounter an error after the first click: core.js:4352 ERROR TypeError: Cannot read property 'imie' of undefined at HttpTestC ...

Invalid file name detected during the download process

Below is the Javascript code I currently use to download a pdf: var link = document.createElement('a'); link.innerHTML = 'Download PDF file'; link.download = "Report.pdf"; link.href = 'data:application/octet-stream;base64 ...

I need help figuring out how to showcase the following object in an Angular 5 HTML file

The console screenshot above shows an object with two values: users and tickers, each being an array of values. How can I display these values in an Angular 5 HTML template similar to the screenshot above? I attempted to use ngFor but encountered errors. ...

The two-way binding does not connect the property and event halves to the same target

I am trying to create a two-way binding using reactive forms in Angular. I need to exchange data between the child component and the parent component seamlessly. This is the HTML code for my child component: <input type="text" #name class=&qu ...

The act of exporting an enum from a user-defined TypeScript path leads to the error message "Module not

I have set up a custom path as explained in this particular discussion. "baseUrl": ".", "paths": { "@library/*": [ "./src/myFolder/*" ], } Within this module, I am exporting an Enum. export enum EN ...

Error in Typescript stating that the property 'children' is not found on the imported interface of type 'IntrinsicAttributes & Props'

When I try to import an interface into my Card component and extend CardProps, a yarn build (Typescript 4.5.4) displays the following error: Type error: Type '{ children: Element[]; className: string; border: true; disabled: boolean; }' is not as ...

Creating a consistent template for typing TypeScript generics

Is it possible to modify a generic function so that it can accept an unlimited number of arguments and concatenate them with .'s? This function should be able to handle nested objects with any number of keys. The current code snippet works when manua ...

Utilizing an image as a background using [ngStyle] in Angular 5

I attempted to set the background of a Div element with an image saved in the database using [ngStyle] in Angular, but unfortunately it did not work as expected. <div class="image" [ngStyle]="{'background': ' url(' + imageUrl + &ap ...

Is there a substitute for $sce in Angular 7?

Previously, in Angular 1, we utilized $sce to display HTML tags like this: > <p><strong>xyzz</strong> yttryrtyt <span > style="color:#e74c3c">abc</span>.</p> in a user-friendly format. I am now curious about th ...

Leveraging both the spread operator and optional fields can improve the productivity and readability of your

Imagine you have an object with a mandatory field that cannot be null: interface MyTypeMandatory { value: number; } Now, you want to update this object using fields from another object, but this time with an optional field: interface MyTypeOptional ...

Empty nested Map in POST request

I am currently working on a springboot application with a React/Typescript frontend. I have defined two interfaces and created an object based on these interfaces. export interface Order { customer_id: number; date: Date; total: number; sp ...

Unable to locate the name 'Cheerio' in the @types/enzyme/index.d.t file

When I try to run my Node application, I encounter the following error: C:/Me/MyApp/node_modules/@types/enzyme/index.d.ts (351,15): Cannot find name 'Cheerio'. I found a suggestion in a forum that recommends using cheerio instead of Cheerio. H ...

I want to swiftly display the API response using console.log in Angular 8

My current setup involves using a service to log the response from a News API like this: import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; @Injectable({ providedIn: 'root' }) exp ...

What is the process for defining the root of a project in ESLint?

I've been working on a project using Next.js and Typescript. My imports look like this: import Component from "/components/Component/Component";, with the root directory being specified as /src. This setup works fine in Next.js, but ESLint k ...

Here's a revised version: "How to link a lambda layer with a function in a serverless.ts file using the

When working with the serverless framework using the typescript template, a serverless.ts file is generated. I am currently integrating lambda layers with existing functions and encountering a typescript error. The error message reads: "Type '{ Ref: ...

The switch statement and corresponding if-else loop consistently produce incorrect results

I'm currently facing an issue where I need to display different icons next to documents based on their file types using Angular framework. However, no matter what file type I set as the fileExtension variable (e.g., txt or jpg), it always defaults to ...

Exploring Custom Validator Comparisons in Angular

Having trouble comparing two input values in a custom validator. An error should occur if the minValue exceeds the maxValue. FormGroup: sumFormGroup = this.formBuilder.group({ from: ['', [Validators.min(0), sumValidator]], to: [&ap ...