Can you please give me the definition of configuring BlockUi Angular annotations dynamically?

Dealing with a repeatable component where each instance requires its own unique blocker, I thought to myself "Okay, that makes sense."

I have already implemented a blockUI that is supposed to activate for all components with a specific defined string. To manage the modularization, I tried creating a dynamic annotation using a guid. The challenge is ensuring that both the template and annotation refer to the same thing.

To resolve this issue, I decided to generate a GUID for each component, named: widgetGuid. When examining the block property during initialization:

@BlockUI(`widget-content`) block: NgBlockUI;

I noticed there was a name property that could be set. Therefore, during initialization, I executed the following code:

this.block.name = `${this.block.name}-${this.widgetGuid}`;

Then in the markup, instead of using a static string, I updated it to:

// I also attempted some hardcoding as well: 
//    *blockUI="'widget-content'+widgetGuid" and that also failed.
*blockUI="block.name"

However, it seems that once I started modifying the block name, the spinners stopped functioning properly.

I'm certain this issue has been encountered before, but I'm not sure where I might have gone wrong.

Answer №1

Exploring NgBlockUi, I discovered a method to achieve this specific functionality.

Interestingly, we can omit the decorator but still require the assignment variable.

import { NgBlockUI } from 'node_modules/ng-block-ui';
import { BlockUIInstanceService } from 'ng-block-ui/lib/services/block-ui-instance.service';
import { Guid } from "src/utilities/guid.ts";  //Utilizing a TS Guid Generator.

export class TestComponent implements OnInit {
    block: NgBlockUI;

    constructor( private _blockService: BlockUIInstanceService) {}

    ngOnInit() {
        let blockName = `widget-content-${Guid.newGuid()}`;
        this.block = this.blockService.decorate(blockName);
    }
}

Implementation in HTML:

<div *BlockUI="block.name">Hello World</div>

Hence, each instance of the Component receives a distinct guid for unique referencing of blocks.

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

Why is the 'as' keyword important in TypeScript?

class Superhero { name: string = '' } const superheroesList: Superhero[] = []; const superheroesList2 = [] as Superhero[]; As I was exploring TypeScript, I stumbled upon these two distinct methods of declaring an array. This got me thinking w ...

Customizing a ng-template with my own HTML content - a step-by-step guide

As I work on creating a custom web component inspired by the accordion component from ng-bootstrap, I'm currently experimenting with the functionality. Feel free to test out the original component on stackblitz. One specific feature I am aiming for is ...

Utilizing string literals as index signatures

I've created a code snippet called MyTest that maps over an object: type MyTest<T> = { [P in keyof T]: T[P]; }; type Result = MyTest<{hello: 'world', foo: 2}>; // ^? type Result = { hello: 'world', foo: 2 } ...

ts:Accessing the state within a Redux store

In my rootReducer, I have a collection of normal reducers and slice reducers. To access the state inside these reducers, I am using the useSelector hook. Here is my store setup : const store = configureStore({reducer : rootReducer}); Main Reducer: const ...

How can I populate an array using values from a different array in Angular?

I am facing an issue with populating three other arrays based on the property 'game type' from my array called 'my games'. Here is an example of the structure of the 'my games' array: hideScore: true, started: true, startedAt: ...

What is the process for integrating the node-menu package into my project without utilizing the require statement?

Is there a way to incorporate node-menu into my TypeScript project without using require, like this: const menu = require('node-menu'); Whenever I attempt to import node-menu into my project, I encounter the following errors: https://i.sstatic. ...

Error: Attempting to access undefined properties (specifically 'toLowerCase') in setup.js is not possible

I'm completely new to this and encountering an error with my code. When I run this command on Discord, I get a TypeError: Cannot read properties of undefined (reading 'toLowerCase') without any error log appearing in the terminal/console. Ca ...

Creating callback functions that vary based on input variables

Consider the following code snippet, which may seem somewhat contrived: arbitraryFunction( // Input that is dynamically generated [ returnValue("key1", "a"), returnValue("key2", 1), returnValue ...

Can TypeScript declaration doc comments be translated and displayed in hover info and suggestion descriptions in VS Code?

English is not my native language, so I am wondering if there are translated versions available for the boxes that appear when hovering over a declaration to provide descriptions/documentation. For instance, with the String.prototype.split() method: ...

Maintain the Http Connection request header active when using Angular with Spring Security

During the process of converting my AngularJS project into Angular 4, I encountered an issue with maintaining the Http connection after logging into the application. The request I am making is: POST /myapp-services/login.html?username=admin&password= ...

Tips for troubleshooting an Angular app with just a single click using WebStorm!

After conducting some research, I have checked the following resources: How to debug an application in Angular2 using angular-cli? https://manuel-rauber.com/2016/09/30/how-to-debug-angular-2-with-webstorm/ The troubleshooting method mentioned on the Je ...

Entering the appropriate value into an object's property accurately

I am currently facing an issue with typing the value needed to be inserted into an object's property. Please refer below. interface SliceStateType { TrptLimit: number; TrptOffset: number; someString: string; someBool:boolean; } inter ...

Measuring the height of an element within its parent component using Angular 4

Check out my demo here I've created a basic parent component along with a child component. Is there a way to retrieve the height of the parent div from within the child component? import { Component, Input, ElementRef, OnInit, ViewChild } from &apo ...

Actions should be pure objects. Employ specialized middleware for handling asynchronous actions in Redux

I've encountered a dispatch error while using redux with TypeScript. It would be really helpful if someone could assist me in correcting the setup I currently have: Store: import { configureStore, combineReducers, MiddlewareArray, } from &ap ...

Unraveling the RxJs enigma: Sharing a stream and selectively retrying it upon fresh subscription

Scenario: Our web application has the capability to show multiple help panels simultaneously. When a panel requires a specific ID (ex: help-id-1), we make a call to an API with that ID and retrieve the necessary help content. Sometimes, we may need to ...

Expanding worldwide in TypeScript

Is there a way to globally add fetch in TypeScript without explicitly using "(global as any).fetch" every time? (global as any).fetch I attempted this by creating a file in ./types/index.d.ts I also tried referencing it by including the file in tsconfig. ...

Tips for creating a dynamic interface in TypeScript to eliminate repetitive code

Currently, I am utilizing typescript alongside the react-navigation library within my react-native project. Following the guidelines provided in the official documentation, I have been annotating my screens. One issue I have encountered is the repetitive ...

Is there a way to change a .pptx document into a base64 string?

Currently, I am working on a project that involves creating an addin for Office. The challenge I am facing is opening other pptx files from within the addin. After some research, I discovered that I need to use base64 for the PowerPoint.createPresentation( ...

Struggling to make HttpClient Post work in Angular 5?

I'm facing an issue with my httpClient post request. The service is not throwing any errors, but it's also not successfully posting the data to the database. Below is the code snippet: dataService.ts import { Injectable } from '@angular/c ...

Angular 5 form validation - validating user inputs

I am currently developing a MEAN stack application and working on implementing form validation. Everything seems to be functioning correctly except for the paragraph tag containing the error message, which is not displaying properly. Additionally, I want a ...