AngularJS push not reflecting changes in one div but working correctly in another unspecified div

I'm encountering an issue where adding a new contact is updating the ul-li list, but not the select-option list.

Here is the code snippet:

<!DOCTYPE html>
<html ng-app>
<head>
<title>Hello World, AngularJS - ViralPatel.net</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>

<script>
    function ContactController($scope) 
    {
        $scope.contacts = ["<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf4f5dcf9f1fdf5f0b2fff3f1">[email protected]</a>", "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b9d1dcd5d5d6f9dcd4d8d0d597dad6d4">[email protected]</a>"];

        $scope.add = function() {
        $scope.contacts.push($scope.newcontact);
        $scope.newcontact = "";
        }
    }
</script>

</head>
<body>
<div ng-controller="ContactController">
    <select ID="select-add-new-product-brand-name">
        <option  ng-model="selectedItem" ng-repeat="contact in contacts" value={{contact}}>{{ contact|uppercase }}</option>
    </select>
</div>

<div ng-controller="ContactController">
     Email:<input type="text" ng-model="newcontact"/>
    <button ng-click="add()">Add</button>

     <ul>
        <li ng-repeat="contact in contacts"> {{ contact }} </li>
    </ul>

</div>

</body>
</html>

I need help identifying the issue here. Any suggestions?

Answer №1

You are trying to control too much

Check out this plunker for reference

Simplify your code by using only one controller

<div ng-controller="ContactController">
    <select ID="select-add-new-product-brand-name">
        <option  ng-model="selectedItem" ng-repeat="contact in contacts" value={{contact}}>{{ contact|uppercase }}</option>
    </select>
     Email:<input type="text" ng-model="newcontact"/>
    <button ng-click="add()">Add</button>

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

Disable error display using PHP for the image field with the value stored in $.row['img']

Currently seeking assistance. I have utilized [ onerror=this.style.display="none"] but it suddenly stopped functioning. Unable to find a solution, is there an alternative to the following method? <img class="basicimg" src='.$row['anncimg&apos ...

Is it possible for two different forms to invoke a single Javascript function?

I have a page with two separate formulas. Each formula has its own form with inputs, and both forms call the same Javascript function on key up. However, only the first formula seems to be working. I suspect that changing the structure of the JS file may ...

Retrieve information by performing a search query on two tables in Laravel and VueJS, using specific conditions

Is there a way to retrieve data from both the Employee and Company tables based on a search by Company name rather than Company Id? These tables have a one-to-many relationship. The current search functionality is working well, but any assistance on implem ...

Conceal the iOS virtual keyboard using AngularJS

Is there a simple way to close the soft keyboard on iOS by clicking outside of an input field in an Angular app? I came across a partial solution that looks like this: $scope.hideKeyboard = function() { document.activeElement.blur(); var in ...

Issues have been reported with the SVG filter URL functionality in Angular 4

Hey there! I'm currently working on drawing a line using SVG in Angular and incorporating some filters for glow effects. However, I've run into an issue where the filter URL is not functioning properly in the browser - nothing is being displayed ...

What is the most effective method to prevent the auto-complete drop-down from repeating the same value multiple times?

My search form utilizes AJAX to query the database for similar results as the user types, displaying them in a datalist. However, I encountered an issue where it would keep appending matches that had already been found. For example: User types: "d" Datali ...

optimal method for integrating various javascript components within a single-page application

Looking to create a single page application with the following architecture in mind: Each page or widget serving as an independent, reusable module for this project and potentially beyond A core application that can utilize these external modules, facili ...

Rules for specifying title attribute for tag a in JavaScript

What is the best way to handle conditions for the a tag (links) when it has content in the title attribute? If there is no description available, how should the script be used? For instance: if ( $('a').attr('title') == 'on any ...

Retrieve the user_id without triggering any route

Is there a way to access the logged in user data without needing to make a request to any route or endpoint? //for example, how can I retrieve the id of the logged in user here? router.get('/',function(req,res,next){ //typically we would acce ...

How can you dynamically set a date range using jQuery Datepicker, utilizing both the methods setDate and (minDate and maxDate)?

Within my interface, I have a dropdown menu where I can select the year, alongside another calendar field that utilizes a datepicker feature. The desired functionality is as follows: when I choose the year 2021 from the dropdown, the default date should a ...

What is the method to execute jQuery code after the completion of a fade out effect?

I am attempting to fade out a div upon click while also adjusting some CSS properties. The problem I am encountering is that the CSS properties change during the fade out transition, instead of after it has completed. I would like the values to change onc ...

The Angular scope remains static during service calculations and does not reflect immediate updates

Is there a way to display a message on the scope indicating that a function in a service is currently being calculated and taking a long time? I have set up a simplified example in this jsfiddle: http://jsfiddle.net/rikboeykens/brwfw3g9/ var app = angul ...

The Three.JS Library Offers Dark and Mysterious Textures

I am facing an issue with a model that I created in Blender 2.76b and exported to json for use with three.js 71. When viewed in Blender, the model looks fine. However, when displayed in webGL, the model appears completely black. I suspect that it might hav ...

Upload files either one at a time or in bulk

Encountering an issue with file upload functionality. When uploading multiple files at once, there are no problems. However, when uploading single files one at a time, each new upload overrides the previous one. Looking for a solution to this problem. Be ...

The React component designed to consistently render video frames onto a canvas is unfortunately incompatible with iOS devices

I'm facing an issue with my code snippet that is supposed to draw video frames on a canvas every 42 milliseconds. It's working perfectly on all platforms and browsers except for iOS. The video frames seem unable to be drawn on canvas in any brows ...

What is the process for displaying a view from a controller in Angular?

After successfully updating the Quiz, I would like to display /list. Can someone please guide me on how to achieve this task? this.update = function() { Quiz.update($scope.quiz, $routeParams.id) .success(function() { // render /list }); ...

Babel Compile disrupts the flow of commands

I'm facing an issue while attempting to launch my development server after Babel successfully compiles my files. However, the command chain seems to halt right after Babel displays the compilation success message. Babel has completed compiling 82 f ...

Tips for ensuring the Search button always remains alongside the input bar during resizing with percentages

I've been trying to figure out why the search button is still showing at the bottom left and creating an "l" shape even though I'm using style="overflow: hidden; padding-right: .5em;". Does anyone have any ideas as to what might be causing this i ...

Moving an image that is set to absolute positioning with jQuery

I have a relative positioned div to display the profile icon and the image will be displayed in this div. The positioning of the image is absolute, with top and left determining which part should be displayed. While the display works perfectly, the issue a ...

Wrap each object in a container and then insert its key and values into that container using jQuery

How can I wrap each item and then insert the object's indexes and values into each created wrapper? I've attempted to accomplish this using the following code: $.ajax({ url: "some url", type: "GET", success: function(data) { var data ...