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

Is there a way to modify the scroll ion-content's color scheme?

Is there a way to change the scroll color in Ionic to green, specifically for ion-content? Any suggestions on how I can achieve this? Below is my HTML code: <ion-header> <ion-toolbar> <ion-buttons slot="start"> ...

The function cb() was never invoked, resulting in an error during the npm install process

I'm having trouble installing node modules in my angular project. Running npm install gives me this error: npm ERR! cb() never called! npm ERR! This is an error with npm itself. Please report this error at: npm ERR! <https://npm.community> ...

The use of 'import ... =' is restricted to TypeScript files

Error: Oops! Looks like there's a hiccup in the code... 'import ... =' is exclusive to TypeScript files. Expecting '=' here. Don't forget the ';'. Unexpected keyword or identifier popping up! package.json ...

Dealing with name conflicts in Typescript when using multiple interface inheritance

Is it possible to securely implement two interfaces in Typescript that both have a member of the same name? Can this be achieved? For example: interface IFace1 { name: string; } interface IFace2 { name: string; } class SomeClass implements IFace ...

Error in Typescript: The 'type' property is not found in the 'string' type

I am working on creating a React component that includes subcomponents within it. I came across this insightful article that has been guiding me through the process. The concept is to design a Modal component with distinct sections such as Modal.Header, M ...

The 'HTMLDivElement' type does not include the property 'prepend' in Typescript

When working with a typescript method, the following code snippet is used: some_existing_div.prepend(some_new_div) This may result in an error message: [ts] Property 'prepend' does not exist on type 'HTMLDivElement'. However, despi ...

Refactor TypeScript in Visual Studio Code: Relocate class from one file to another (already existing) file

One common task when reorganizing a project with numerous classes is to transfer certain classes to an already existing file. After exploring various vscode features and extensions, I have not come across any refactoring tool that allows for this specific ...

What impact does introducing a constraint to a generic type have on the inference process?

Let's take a look at this scenario: function identity<T>(arr: T[]) { return arr } identity(["a", "b"]) In the above code snippet, the generic type T is inferred as string, which seems logical. However, when we introduce a ...

Issue in VueJs where mutations do not properly save new objects to the state

I am facing an issue with updating my vuex store after modifying my user credentials in a component. Below is the code snippet for reference: mutations: { updateUserState: function(state, user) { state.user = user; }, } actions: { updat ...

What steps can I take to resolve the problem of my NativeScript app not running on android?

When I entered "tns run android" in the terminal, the default emulator API23 launched but my app didn't install. Instead, an error occurred. This is different from when I run it on the IOS simulator, which runs smoothly without any errors. The nati ...

The function Array.foreach is not available for type any[]

I'm encountering an issue where when I attempt to use the ".forEach" method for an array, an error message stating that the property 'forEach' does not exist on type 'any[]' is displayed. What steps can I take to resolve this probl ...

Attaching events to dynamically generated HTML in Angular

I'm working on my Angular (6) application which utilizes a charting library that generates the chart and its corresponding HTML after the component has been initialized. Currently, I am facing an issue where I need to implement events, specifically a ...

Incorporating DevExtreme into an Angular application

After following the suggested command to add DevExtreme to my angular project using npx -p devextreme-cli devextreme add devextreme-angular, I encountered an issue related to node-modules/sass/embedded or a self-signed certificate problem. Despite trying s ...

The data stored in a FormGroup does not automatically transfer to FormData

I am currently facing an issue with uploading multi-part data to my API. To achieve this, I have created a FormData object for the upload process. Initially, I gather all the necessary user input data such as an image (file) and category (string). These va ...

Exploring nested grandchildren components in Angular2 Dart

Currently, I am attempting to make the following code work in Angular2 Dart: <div class='test'> <accordion2> <accordion-item-2 title="blah" active="true"> <sample-form-1></sample ...

The EmailInstructorsComponent is missing a component factory. Make sure you have added it to @NgModule.entryComponents

I am currently utilizing the ngx-admin template and attempting to create a modal that will open upon clicking a button. My goal is to display a form within the modal window, however, upon clicking the button, the modal opens but the form does not appear, r ...

Received an error while using Mongoose 6 $group with Typescript stating that the property '_id' is not compatible with the index signature

Recently, I've been transitioning from JavaScript to TypeScript and also upgrading from mongoose 5.8 to version 6.1. The code snippet below used to work perfectly before: let getActionsTakenByApp = (store_url: string) => { return AppAction.aggr ...

The most accurate type to determine after verifying that `typeof a === 'object' && a !== null` is the following

Within my codebase, there exists an assertion function that verifies a given value is an object (using the typeof operator), with the exception of null: export function assertIsJavaScriptObjectExceptNull(value: unknown) { if (typeof value !== 'obj ...

Why is the imported package not being recognized in the namespace declaration of my Node.js TypeScript file?

Currently, I am utilizing the WebStorm IDE developed by JetBrains to modify a TypeScript file within a Node.js v8.6.0 project. The JavaScript version set for this project is JSX Harmony. In the beginning of the TypeScript source file, there is an import st ...

watcher using RxJS

After recently diving into the Observable and Observer pattern, I came across various resources that describe Observable as a producer and Observer as a consumer. However, as I analyzed the code snippet below, I found myself puzzled by the role of the obse ...