Create a unique key dynamically based on a specified scope value using AngularJs

I am working with an angular directive that utilizes a title with a key from a messages.properties file. To dynamically generate the key, I want to concatenate 'root.' + scope.value + '.title' like so:

titre="{{ 'flux.' + 'typeFlux' + '.title' }}"

This should result in titre="{{ 'flux.typeFlux.title' }}"

Can anyone advise on how to achieve this within my html file?

Thank you.

Answer №1

When facing this scenario, the recommended approach is to implement Object Bracket Notation. By doing so, you can utilize the dynamic part of the expression as a reference to an object property, as illustrated below:

{{flux[typeFlux].title}}

http://plnkr.co/edit/OHK7XqZyv2eKhrOROkqi?p=preview

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

Storing repeated inputs in local storage multiple times

I am working on a feature where I need to store data in local storage multiple times using a dropdown menu and some input fields. Currently, I am able to retrieve all the values from the input fields and see them in the console log. My goal is to save thes ...

An error was encountered due to an unknown provider: storeProvider. This occurred in relation to Auth0 within an AngularJS application

I've been working on integrating Auth0 into my NodeJS/AngularJS project (hosted on Cloud9) by following these guidelines: https://auth0.com/docs/client-platforms/angularjs#create-an-application-instance I downloaded the provided sample and compared t ...

Two-way data bindings trigger the digest() function to iterate 10 times

I'm facing issues with angular binding and my experience level in this area is limited. I will be posting all related questions here. I have a piece of angularjs code that is triggering 10 digest() cycle reached errors. After researching similar posts ...

``How can I effectively handle and display Angular JSON text in an alert message?

Is there a way to pass a JSON entry into the onClick event for triggering an alert box in AngularJS? I'm attempting to display a message box with the content of a specific JSON entry when clicking on a row within a table. The issue seems to be isolat ...

Troubleshooting $templateCache not functioning correctly within the Angular.js angular-config

I keep encountering an error message that says "angular.min.js:6Uncaught Error: [$injector:modulerr]" whenever I try to implement $templateCache in my app.config block. Interestingly, when I remove the $templateCache parameter from app.config, the errors d ...

Utilize Javascript to establish a fresh attribute by analyzing other attributes contained in an array within the object

Currently, I am working on a data structure that looks like this: masterObject: { Steps: [ { step: { required: false, }, step: { required: false, }, step: { required: false, }, }, ] } ...

mvc data binding without any assistance

I'm interested in understanding how model binding functions when not utilizing razor but instead relying on a client side framework like knockout or angular. For example, the model binder typically needs something along the lines of [0].Collection[0] ...

What is causing my Directive to trigger the error "Error: $injector:unpr Unknown Provider"?

I have been diligently working on updating my Controllers, Factories, and Directives to align with the recommended Angular Style Guide for Angular Snippets. So far, I have successfully refactored the Controllers and Factories to comply with the new style ...

Is it possible to utilize href alongside the urlRouterProvider?

Within my angularjs application, I opted to switch from using ngRoute (routeProvider) to ui.router (urlRouterProvider) module and stateProvider for transitioning between different states in the app. However, I recently discovered that ui-router only suppo ...

AngularJS: Recommendations for structuring code to dynamically update the DOM in response to AJAX requests

Within Angular's documentation, there is a straightforward example provided on their website: function PhoneListCtrl($scope, $http) { $http.get('phones/phones.json').success(function(data) { $scope.phones = data; }); $scope.order ...

What is the best way to invoke a function within an AngularJS controller?

Currently, I am exploring the most efficient method of calling a function from an AngularJS controller externally. In our setup, data is transmitted from a Python backend to the frontend using JavaScript functions. To feed this data into the Angular contr ...

Different approaches to verifying a password match on the signup page with angularjs

I need help with writing code to check the confirm password using AngularJS. Can someone please assist me with this issue? Here is my signUp.html file: <html ng-app="UniqueApp"> <head> <link rel="stylesheet" href="../css/bootstrap.min.css" ...

Issue: ui-route failing to function properly when the href attribute is utilized

I am currently working on implementing ui-route to manage the states of my app while focusing on URL navigation. My goal is to enable users to simply click on a link and be directed to the state associated with the specific URL. After following an In-Dep ...

Transforming Angularjs into Vuejs

I am currently transitioning a chat application from AngularJS to VueJS, but I am facing some challenges as I am not very familiar with AngularJS. Unfortunately, there is a lack of comprehensive resources available for me to gain a better understanding of ...

Dealing with ng-repeat and button alignment across Chrome, Edge, and Firefox

Can someone help me understand this strange behavior I am experiencing across all browsers? <div style="margin-top:5px"> <button translate="clear" ng-click="xyz.clear()" class="btn btn-default"></button> <butt ...

AngularJS chatbox widget for interactive communication

Currently, I am in the process of developing the back-end for a web application utilizing angularJS. One of the key features is allowing users to communicate with each other through a pop-up chat box similar to those found in Gmail or Facebook. My goal is ...

Troubleshooting: Why Your Angular Data Binding is Failing

I am integrating a WCF REST service with an AngularJS application. My goal is to retrieve account information based on the account number provided, however, I am encountering an issue where the text "Account_Type" is displayed three times before showing th ...

Tips for toggling visibility in Angular 2

I utilized [hidden] in the following way where the value of "secondTab" is set to true. <form #siteForm="ngForm" novalidate (ngSubmit)="saveSite(siteForm.value,siteForm.valid)" class="admin-modal"> <div class="txt-danger">{{errorMessage}}&l ...

Customizing order and limit features in AngularJS

I have a collection of items that I need to organize into separate lists based on priority levels. items = [ {'type': 2, 'priority': 1, 'name': 'one'}, {'type': 1, 'priority': 2, 'na ...

Exclude a select few rows in MatSort, rather than excluding entire columns

When the user clicks on the Date column for sorting, it is required to exclude empty rows from the sorting. Empty rows are present due to the application of ngIf on those particular rows. The requirement states that rows with empty column values should eit ...