Angular2: Implementing a restricted access control system for permitted user actions

Within my application, there are various projects each with their own set of actions or buttons such as like, share, and edit. However, not all users should have access to every action. In fact, some users should not even see certain buttons.

To address this issue, we have implemented a system where the server returns an array of actions as strings. For example:

["updateLike","editProject","withdraw"]

In our template, we iterate through this array using *ngFor directive to display the buttons:

<button *ngFor="let action of allowedActions"> {{ action }} </button>

While this successfully displays the actions, we still need to determine how to execute these actions onclick. What is the proper syntax for this task? Should we consider using a mapper? Additionally, we may extend the array to include multilingual button texts in the future.

Answer №1

In order to execute functions, you will need to assign a click event. It is recommended to avoid grouping all buttons in an array and instead treat them as individual entities. Apply ngIf on each button based on your conditions for better control.

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

Guide on translating text in Angular Material Snackbar using ngx translate

I have successfully integrated ngx translate into my project, allowing me to convert text on HTML pages into different languages using JSON files. However, I am facing a challenge in changing the language of the text displayed in the "Snackbar" component i ...

Conceal Columns in DevExtreme with Angular2 EditMode

Is there a way to conceal a DataGrid Column while in EditMode by utilizing DevExtreme and Angular2? <h3>Test</h3> <dx-data-grid id="gridContainer" [dataSource]="xxx" [allowColumnReordering]="true" [allowColumnResizing]="true" [rowAltern ...

Angular: Modules that are lazily loaded are only loaded into memory and executed, but

I am facing an issue with lazy loading in my Angular application. I have an AppModule that lazily loads MainModule, which in turn lazy loads HomeModule. The problem is that while MainModule loads fine, HomeModule gets loaded but is not rendered inside the ...

Having trouble with Angular 2 and ng2-file-upload when trying to load it using SystemJS

Currently, I am utilizing systemJS for package management in my project. In order to configure systemJS, I have included the following lines in the configuration file: { map: { 'ng2-file-upload': 'node_modules/ng2-file-upload' }, p ...

I am looking to integrate a "reveal password" feature using Bootstrap 5

I had hoped for something similar to this Image from bootstrap However, what I ended up with was this Image on my local host This is the code I have: <input type="password" class="form-con ...

Tips for effectively passing an array to props in Vue when leveraging Typescript and the class component decorator

I'm currently struggling to understand the proper method of passing an array as a prop to a component in Vue, using Typescript and the class component library. Following the official template, I attempted the following approach: <script lang="ts"& ...

Issue with Angular router failing to load the correct component

As a novice with Angular, I have the following routes set up. app.routing.module.ts import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; import { FrameComponent } from './ui/frame/frame.compon ...

Create a custom data structure resembling a record, where certain keys are assigned specific value types

My objective is to establish a custom type resembling a record, where certain keys are designated for specific value types. The proposed object would look something like this: const o: TRec = { text: "abc", width: 123, height: 456, //...an ...

Learn how to open a component in a new browser tab using Angular from a different component

I wish to display the MapComponent in a new browser tab when a button in my AppComponent html file is clicked. Currently, when I click the button, the MapComponent opens in a new tab but it also displays the button. How can I configure it so that only the ...

SystemJS could not locate the root directory for RxJS

There seems to be an issue with SystemJS loading rxjs modules on Windows, as it throws a 404 Not Found error on the rxjs directory. This problem does not occur on OSX, and all modules are up to date. GET http://localhost:8080/node_modules/rxjs/ 404 (Not F ...

Transform the header elements into clickable links

How can I prevent the header items from acting as links when I right-click on them? Here is my code: (I don't want them to open in another window when right-clicked.) [![enter image description here][1]][1] ...

Issue: This feature cannot be accessed when using the Angular CLI outside of a project workspace during a legacy application migration

Currently working on updating a legacy Angular application where I need to address some vulnerabilities. After updating the node image in the Docker file (which was also updated previously), I encountered the following issues. Unfortunately, I'm havin ...

Creating the document.ready function in Angular2 with JQuery

I am seeking assistance to modify the JQuery function so that it can run without the requirement of a button click. Currently, the function only executes when a button is clicked. Code declare var jQuery: any; @Component({ selector: 'home-component ...

Interference of NestJS provider classes in separate event loops causing conflicts

I'm currently facing an issue where my shared library injectables are conflicting with each other. The bootstrap file initiates this file alongside a proxy server to start local microservices import { serviceA } from '@company/serviceA' imp ...

Difficulty in activating or deactivating form controls in Angular 2 upon receiving an HTTP response

When using formcontrol in Angular, I encountered an issue where I tried to disable the form control based on a variable assigned from an HTTP response. Angular2 gave me a warning message. The warning mentioned that it's not recommended to use the dis ...

An unexpected error occurred in the Angular unit and integration tests, throwing off the script

I seem to be facing a recurring issue while running unit/integration tests for my Angular project using Karma. The tests have a 50:50 success/failure rate, working fine on my machine but failing consistently on our build server, making the process quite un ...

Tips on efficiently sorting through items using Angular Material's autocomplete feature

Struggling to implement a filter on an angular material autocomplete form input. The issue arises when attempting to filter values with an array of objects. After forking the example from the angular material documentation, I made adjustments to handle ob ...

Is it possible for the ionic ionViewDidEnter to differentiate between pop and setRoot operations?

I am facing an issue with my ionic 3 page where I need to refresh the data on the page only if it is entered via a navCtrl.setRoot() and not when returned to from a navCtrl.pop(). I have been using ionViewDidEnter() to identify when the page is entered, bu ...

The issue arises when attempting to apply CSS styles to an existing component or body tag,

I am currently working on an Angular 7 project where I have a requirement to dynamically load a component using routes. However, when I try to add styles for the body tag and existing component tags in the dynamically loaded component style-sheet, they do ...

Inquiry on SSGHelpers and GetStaticProps functionality with parameterization

I am currently implementing createProxySSGHelpers to prefetch data using trpc in a project I'm developing, but I'm facing an issue where the id from the url params is returning as undefined even though it's visible in the url bar. Below is ...