ngModel' complex structures generation process

Exploring the possibility of utilizing Angular's method for nesting properties deeply, similar to how the ng-model directive accomplishes it. For example, in a view we can create a very complex object within a scope by specifying:

ng-model="data.obj1.prop2.attr3.value4.text"
. The goal is to achieve this level of nesting easily within a controller or service without needing to reinvent the wheel or resorting to external solutions found on sites like this or this. Is there perhaps an undocumented function such as angular.create(path_str) that could facilitate this process?

Answer №1

To accomplish this, you can utilize the $parse service. It provides a getter and setter function that should be able to meet your requirements.

    var getter = $parse('prop1.prop2.prop3.prop4');
    var setter = getter.assign;
    setter($scope,"value1111");

You can view an example in this fiddle http://jsfiddle.net/cmyworld/m7gxn/

Additionally, this alternative method may also work

$scope.$eval("prop2.prop2.prop3.prop4=55");

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

Passing an HTML5 video element as a prop in Vue.js

I am attempting to pass an HTML5 video as a property from a parent component to a child component in Vuejs. Parent Component: <template> <div> <video ref="video"> <source src="@/assets/video.mp4" type= ...

Guide to pulling and showcasing information from XML at 30-second intervals using JQUERY AJAX and HTML

Seeking assistance as a beginner. Looking to retrieve and showcase data (HTML / PHP page) from XML every 30 seconds. XML FILE : <MAINData> <LiveData> <Field no="1">ENG ODI</Field> <Field no="2">ENG</Field> ...

sound not functioning on iPad

<audio id="example" controls="controls"> <source src="1.mp3" type="audio/mpeg" /> <source src="1.ogg" type="audio/ogg" /> </audio> JavaScript code to automatically play video when the page loads document.getElementById(&ap ...

What is the correct way to chain Promises for the tasks of creating a new user and hashing their password simultaneously?

My goal is to send a POST request to create a new account. The process involves checking if an account with the same email exists. If not, a new account is created and stored in a user collection. Additionally, password hashing and token generation are per ...

"Vue: Elevate Your Design with Seamless Color Trans

I am faced with the challenge of creating a transition effect for an overlay color when a button is clicked using Vue. Currently, the overlay appears abruptly, but I would like it to smoothly transition from a darker shade to a lighter one. As a newcomer t ...

JavaScript: Remove duplicates and count the number of unique properties in an array

Arrays have always been a challenging aspect for me, so I would really appreciate any assistance. ...

Modify the scope in the middle of a scope function

UPDATE: I've created a JSFiddle: http://jsfiddle.net/U3pVM/18137/ I'm looking to make the black section move up FIRST, followed by the green sliding across. I'm struggling to achieve this effect. Keep reading for more details: Note: The co ...

Is there a way to transfer the value from one directive to another directive template and access it in a different directive's scope?

I attempted to pass the directive attribute value to a template ID, which can then be used in another directive. Below is my index.html code: <my-value name="jhon"></my-value> Here is the JavaScript code: .directive('myValue',func ...

Error: The function seems to be malfunctioning or missing

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $('div'); // <--- THIS DOESN'T WORK </script> An issue has been encountere ...

Is javascript or ajax the best choice for updating a database in asp.net mvc?

I need help with updating a row in my database based on a change event from a dropdown list. I am not sure whether to use javascript or ajax for this purpose as I want to avoid page refresh. Any recommendations on which method is best and where I can find ...

Regular occurrences of heap memory exhaustion within a node.js application running in a docker container

My node.js application consists of 16 microservices, a docker image, and is hosted on the Google Cloud Platform using Kubernetes. However, when handling API requests from just 100 users, some of the main docker images are crashing due to heap out of memor ...

How can I activate a function or pass a selected value to a different scope variable using AngularUI Bootstrap Datepicker?

Check out this AngularUI Datepicker demo on Plunker: http://plnkr.co/edit/DWqgfTvM5QaO5Hs5dHco?p=preview I'm curious about how to store the selected value in a variable or trigger another function when a date is chosen in the field. I couldn't ...

What is the best way to serve index.html from a Node.js/Express application?

I am attempting to serve the index.html file from my node/express app, but I am encountering some difficulties. This is my server.js: const express = require('express'); const path = require('path'); const http = require('http&ap ...

Using Selenium to continuously scroll to the bottom of the webpage

Selenium: I am new to WebDriverJS. I have experimented with this method in Java. Long repeat = 0l, scrollHeight = 0l, returnHeight = 0l; while(true){ if (repeat == 0) { returnHeight = (Long) jse.executeScript("var scroll =document.documentEle ...

Can JSON files be used to store arrays with multiple dimensions?

I'm attempting to save a "multidimensional array" in a json file that will be used in JavaScript, essentially an array containing multiple arrays. Is this doable? If so, how can I achieve it? I tried formatting it the same way as in JavaScript, but it ...

Running the command "npm start" is resulting in an error message stating: "ENOENT: no such file or directory ... package.json"

After successfully creating a React app using NPX, I encountered an issue when trying to run npm start. The error message that appeared is as follows: $ npm start npm ERR! code ENOENT npm ERR! syscall open npm ERR! path C:\Users\Administrateur.TE ...

Modify the styling of the initial picture in a Google Drive file

Having an issue.. I am working on a website where each page is managed through Google Drive. I need to change the CSS styling of only the first image on one specific page. Using :first-child won't work because the HTML structure contains "p > span ...

Implement a Codeigniter model that utilizes JavaScript to insert an ID

Is there a way to retrieve the productid value in PHP code? function getunitstock(){ var productid = document.getElementById('product').value <?php $prodbyid = $this->pos_model->get_productbyid(+productid+)?> document. ...

Implementing JSON web tokens on the client side using Node.jsHere are the steps to implement

I have been developing a Node.js express application with JWT for authentication to secure access to my admin page. While testing my routes using Postman, everything works smoothly on the server side. However, I am facing a challenge on the client side in ...