What is the best way to accurately establish a new name for the evolving scope

var tags_offset=[];
$scope.getRelations = function(id, ref, subRef=0){

    tags_offset[ref+'-'+subRef]=0;
    $http.get( CONS.appHttp+ '/tags.php?ID='+id
         +'&ref='+ref
         +'&contentType='+subRef
         +'&offset='+tags_offset[0] ).success(function( data ){
             if(tags_offset > 0){
                 $scope.tagRelations[ref+'-'+subRef] = $scope.tagRelations[ref+'-'+subRef].concat( angular.fromJson( data ));
                 $scope.tagRelations[ref+'-'+subRef].next = data.next;
                tags_offset[ref+'-'+subRef]++;
             }else{

                 $scope.tagRelations[ref+'-'+subRef] = angular.fromJson( data );
                 tags_offset[ref+'-'+subRef]++;
             }
    });
}

I would like the format to be like this: $scope.tagRelations.((ref+'-'+subRef)) for example

$scope.tagRelations.content-1

$scope.tagRelations.video-2

I want to modify

$scope.tagRelations[ref+'-'+subRef]
...........................................................................

Answer №1

It is not possible.

In order to access properties using dot notation, the property names must be valid identifiers. Since `-` is considered an operator (specifically the subtraction operator), it cannot be used in an identifier name.

To access properties with names that are not valid identifiers, square bracket notation must be utilized instead.

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

Unable to interact with the reappeared element selected using jQuery

After using developer tools in both Chrome and Firefox, I successfully created an XPath for a specific element. However, when attempting to click on the element by hovering over the returned value $x(xpath), I encountered an error. The error message read: ...

Error: The socket.io client script cannot be found when using Express + socket.io

This situation is really getting to me... even though I have a functioning version of Express + Socket.io, I can't replicate it in a new project folder with standard NPM installs. Can someone please help me figure out what I'm doing wrong...? Her ...

What advantages do interfaces as data types offer in Angular compared to using classes?

After watching a tutorial from my teacher, he showed us this code snippet: He mentioned that the products array, defined as type any [], is not taking advantage of TypeScript's strongly typing. He suggested using an INTERFACE instead. I have a questi ...

Generate a new item using an existing one

I am seeking to extract the desired output from the provided input: Input Configuration: var inputParams = { 'inputDetails' :[ { 'field' : 'specificationName', 'value' : 'strong'}, { ...

I'm having trouble with my Laravel edit page not functioning properly when using vue.js. Can anyone help me troubleshoot

Currently, I am developing a dashboard to display details. Users can click on the edit button to modify their information. However, when I try to edit by clicking the button, nothing happens. It seems like the editing feature is not functioning properly, a ...

The initial update of ng-model is not occurring

I am currently working on a checkbox functionality in my project that is bound to an ng-model: <input type="checkbox" ng-change="toggleAll(globalChecked)" ng-model="globalChecked"> The toggleAll function is responsible for accessing the globalCheck ...

What could be causing the lack of change in direction for the initial function call?

There appears to be an issue with image(0) and image(1) in this array that I can't quite understand. The console output shows: i=5; div class="five" id="slides" i=0; div class="one" id="slides" i=1; div class= ...

Finding the average JSON value using d3.js

Here is the structure of a JSON file I am working with: [ {"id":1,"sex":"Female","programming":5, "project":7}, {"id":2,"sex":"Male","programming":8, "project":4}, {"id":3,"sex":"Female","programming":5, "project":6}, {"id":4,"sex":"Male","programm ...

Is it possible to assign the margin-bottom property of one element to be equal to the dynamic height of a sibling element?

I am in the process of creating a website that features a fixed (non-sticky) footer placed behind the main content using the z-index property. The footer only becomes visible when the user scrolls to the bottom of the page, achieved by assigning a margin-b ...

Submit a form utilizing jQuery's ajax function

I am currently facing an issue with my use of the $.ajax post method. My intention is to submit form data on the current page itself, but somehow the script is redirecting to the action page. If anyone could pinpoint what's causing this redirection ...

What is the best way to display time instead of angles in highcharts?

Hey there! I'm currently working with highcharts and I have a polar chart where I want to display time on the y-axis instead of angles. Here's what I've tried so far: On the x-axis, I have angles and I've set tickInterval: 45,. How can ...

Developing Angular dynamic components recursively can enhance the flexibility and inter

My goal is to construct a flexible component based on a Config. This component will parse the config recursively and generate the necessary components. However, an issue arises where the ngAfterViewInit() method is only being called twice. @Component({ ...

What steps can I take to troubleshoot the "Element type is invalid" error in my React application?

I am currently restructuring my initial code for better organization. Click here to view the code on CodeSandbox. However, I'm facing issues with integrating child components into my code. For example, in this instance, I showcase how I import a chi ...

Instructions on obtaining a distinct daily array from the weather API array that provides a detailed 5-day weather report every 3 hours

Seeking assistance with my weather app development on React using axios with the openweathermap.org API. Currently stuck on getting data formatted in a specific way from the 5-day forecast it provides, totaling 40 reports over the 5 days. The API response ...

How to retrieve values from checkboxes generated dynamically in php using jquery

This is a unique question and not related to event binding or any suggested duplicates. Hello, I am facing an issue while trying to fetch the value of a checkbox to send it in an ajax request to a PHP page. The checkboxes are dynamically created using PHP ...

Performing mathematical calculations using javascript

In my project, I'm utilizing HTML, CSS, and JavaScript to achieve the following: Dropdown menu for Category (Coffee Appliance) Dropdown menu for Product (Keurig Coffee Maker) Wattage: 1500kWh (auto-filled from Local Storage) Daily Energy Con ...

Changing the default download directory in Selenium using JavaScript

How can I use JavaScript to change the default download directory? I have a list of folders and one is named "C:\Study\Selenium". How do I update the location for downloaded files to this specific path in my code? chromeOptions.setUserPreference ...

Manipulate HTML injected in real-time to adjust size within a preview container using Angular-UI

Within my Angular-UI modal view, I have a preview feature: <div class="wrapper bg-white b-b ng-binding" ng-bind-html="item.content" style="overflow:auto"></div> Currently, I am using style="overflow:auto" to show scroll bars when the inserted ...

Use jQuery's $.post method to validate the form field and prevent submission if there are any errors

I am trying to validate a form field on submit and block the submission if an ajax response message is returned. Below is the JS code I have: $('form.p_form').submit(function (){ var description = $.trim($('#f9').val()); var aa = $.pos ...

Determine if an object is already present in a JSON array by comparing their respective IDs

I have a shopping cart stored in JSON format. [{"tuote":{"id":"2","name":"Rengas 2","count":16,"price":"120.00"}},{"tuote":{"id":"1","name":"Rengas 6","count":"4","price":"25.00"}},{"tuote":{"id":"4","name":"Rengas 4","count":"4","price":"85.00"}}] Form ...