Issue with Angular ng-Model not appearing on the second attempt

Within a modal popup that appears based on certain conditions, everything functions normally the first time it is displayed.

The code in question is as follows:

<div class="form-group">
    <p>First Name:</p>
    {{vm.user.name_first}}
    <input type="text" class="form-control" ng-model="vm.user.name_first" name="firstName" required />
</div>

Upon reopening the modal after closing it, the text below the p tag displays correctly. However, the ng-model, which contains the same content as the text after the p tag, shows the input field empty instead of displaying the content from vm.user.name_first.

What could be causing this issue to occur only on the second instance?

Answer №1

Give this a try:

<div class="input-group">
<p>Your Name:</p>
{{vm.user.fullName}}
<input type="text" class="form-control" ng-model="vm.user.fullName" name="fullName" ng-model-options="{ getterSetter: true }" required />

Here's why:

Using a getter/setter function with ngModel can be beneficial in certain scenarios. A getter/setter is a function that retrieves the model's value when called without arguments, and updates the internal state of the model when given an argument. This approach is valuable for models with an internal representation different from what is displayed in the view.

Check out the AngularJS documentation for more information on ngModel implementation.

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

Retrieve four distinct values using only a single text box input and display them individually on separate lines

Is there a way to receive four input values from the user using just one textbox and display them on separate lines? function collectData() { var userInput, i; var textOutput = " "; for (i = 0; i <= 3; i++) { userInput = document.g ...

Using Javascript to redirect to a link using JSON

Is there a way to display the CustomerPartial without reloading the page or triggering a postback when a button is clicked? Currently, when I click the button, data is posted to Home/Customer but the browser link always remains as: localhost:49461 How ca ...

The powerful combination of AngularJS and PHP's json_encode functionality provides a robust solution

I have a straightforward code snippet using json_encode and echoing out the response in PHP. Take a look at my code below: app.js $scope.login = function() { var data = { username: $scope.login.username, password: $scope.l ...

Ways to implement a parallax effect by changing images within a specific div on scrolling with the mouse

First and foremost, thank you for taking the time to review my question. I am currently developing a website and I need to implement a vertical image transition effect within a selected division, similar to a parallax effect. Within this div, there are 3 ...

When sending a form with a POST request in NODE, the data can be missing

I'm having trouble with setting up routes in an API and getting data from simple forms. Take a look at this basic HTML form: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>test form</titl ...

Comparing Arrays with jQuery

I am currently working on a tic-tac-toe project that involves a simple 3x3 grid. I have been storing the index of each selected box in an array for each player. However, I am facing difficulty in comparing my player arrays with the winner array to determin ...

Ways to transfer data between Angular controller and jQuery

Looking for some guidance on how to toggle between two HTML divs based on user input validation using an Angular controller and jQuery animations. Each div contains input fields that need to be validated before moving on to the next stage. Here is a simpli ...

Tips on modifying classes within specific sections of HTML tables

I attempted to create calendar-like tables, In my script, I am trying to handle events being registered. My goal is to change the classes of cells from 2 to 5 when they are clicked on, and change the cell colors from first to hovered to aqua. For this p ...

What could be causing Vue Router to only load after I click a link and then refresh the entire webpage?

I have a file called components.js filled with Vue.component instances. Then I have a main.js where I implement a router using these components to create different pages. In index.html, I have links to the router pages. The issue is that on the initial ...

Next.js does not support Video.js functionality when using server side rendering

I'm struggling to set up video.js in my next.js project and encountering issues. When the player is loading, it initially appears black and then disappears abruptly. A warning message in the console reads: "video.es.js?31bb:228 VIDEOJS: WARN: T ...

Unsuccessful translation of HTML symbol codes within a toggle function using jQuery

Is there a way to toggle between the symbols + and - using HTML entity codes &#43; and &#45;? I have attempted different solutions for toggling HTML content, but none seem to work correctly with these specific codes. It toggles once, but doesn&apo ...

What is the best way to link this information to access the data attribute?

Currently, I am looking to streamline the data retrieved from firebase so that it can be easily displayed in a FlatList component. How can I transform my data into a simple array that can be iterated over in the FlatList? UPDATE! I have multiple other coi ...

Finding the earliest and latest dates from an event list in Angular can be accomplished by sorting the dates and

Can someone help me find the earliest and latest date from the list of events? Below is the code snippet along with a screenshot of the console log message. events: Event[] = []; count=0; minDate = new Date(); maxDate = new Date(); constructor(pr ...

Swapping out characters that are not numerical within a text input field

Is there a way to restrict the input in a text box to only numbers (1-5), a $(dollar) .(decimal) and '(singlequote) during a keyup event? I need a method that will replace any characters typed that are not part of this criteria with a *. Can you pleas ...

% unable to display on tooltip pie chart in highcharts angular js

https://i.stack.imgur.com/Ccd7h.png The % symbol isn't displaying correctly in the highcharts ageData = { chartConfig: { options: { chart: { type: 'pie', width: 275, height: 220, marginTop: 70 ...

Utilizing the bind() method in a specific context

I'm currently developing a website where different objects are binding to common events on $(window). However, I need to ensure that these functions are executed within the context of the objects that triggered them. In other words, I want to maintain ...

Having trouble converting binary data to base64 using GridFS-stream

As I attempt to convert some binary data from uploaded images to base64 in order to display an image, the terminal is throwing back this error: TypeError: Cannot read property 'on' of undefined I find it puzzling, as when I post I also utilize ...

Invoking a JavaScript function to retrieve an array of integers from a C# method for organizing columns in datatables.net

I have to admit that my JavaScript skills are not very strong. Currently, I am working on creating a table using datatables.net. The table is being populated by calling a generic handler, which in turn fetches data from the database using C#. This functio ...

Using Laravel and vue.js to convert values into an array

I am currently utilizing vue.js within my Laravel project. Within the project, I have three tables: Article Location article_location (pivot table) I am looking to convert location articles into JSON format so that I can pass it to vue. How should I ...

Angular is able to select an element from a specified array

I'm currently struggling with using Angular to manipulate a TMDB API. I am having difficulty retrieving an item from an array. Can someone provide assistance? Here is the response that the array returns: { "id": 423108, "results ...