Shifting elements within a modal using AngularJS and CSS: Swapping one div out for another

I am currently developing an application and I am considering using AngularJs for this purpose:

<div class="main">
<div class="one">Content 1 goes here ...</div>
<div class="two">Content 2 goes here ...</div>
</div>

Within div one, there is a button that, when clicked, reveals div two and replaces div one.

Can someone provide guidance on how to achieve this? (Should I use ng-Animate or perhaps another CSS technique)

EDIT: Allow me to clarify further Div one contains a list and an ADD button. When the ADD button is clicked, it displays a list within div two. I can then select items to add and submit them, resulting in an updated list being displayed in div one.

Answer №1

Check out this JS FIDDLE example

HTML Code Snippet

<div ng-app="myApp">
<div ng-controller="listCtrl">
    <div class="one">
        <ul>
            <li ng-repeat="list in lists">{{list}}</li>
        </ul>
        <button ng-click="showOptions = !showOptions">{{showOptions?'Hide':'Show'}} Options</button>
    </div>
     <div class="two" ng-show="showOptions">
        <ul>
            <li ng-repeat="list in options" ng-click="add($index)">{{list}}</li>
        </ul>
    </div>
</div>

JavaScript Controller Code

    var myApp = angular.module('myApp',[]);
myApp.controller('listCtrl',function($scope){

    $scope.lists =['Monday','Tuesday'];

    $scope.options =['Sunday','Saturday'];

    $scope.add = function(index){

        $scope.lists.push($scope.options[index]);
         $scope.options.splice(index,1);


    };

});

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

Filter JavaScript elements by conditions and true/false values

I can't quite recall the answer to this at the moment. Consider an array of Vendors (this is just placeholder data): [ { "user_updated": null, "user_created": "128a84b5-275c-4f00-942e-e8ba6d85c60e", "d ...

What is the best way to call the app.js function from an HTML page in an Express.js environment

Is there a way to trigger the function init() { // } located in app.js from an HTML page? <a href='javascript:init();'> Trigger init </a> The issue with the code above is that it searches for function init() only on the client side ...

What are some techniques for streamlining and simplifying complex and repetitive JS/jQuery code?

I've come across this code snippet in a JavaScript file that I need to modify, but it's quite confusing to me. I'm not sure why it has been written this way and I would appreciate some help in understanding its purpose. Can someone break it ...

The implementation of pipelining for server-side processing

Initially, this function is set up to work with $_GET. However, after incorporating feedback from this discussion, I made adjustments to the function which resulted in an error message being displayed by Firebug. The error message reads: "json.aaData is ...

Minimize the number of clicks needed to navigate using the HTML/JavaScript navigation

On my website, I have a navigation bar that changes the contents of a div when a user clicks on an item. However, if the user clicks multiple times in quick succession, the content changes too many times. I want to ensure that the content only changes once ...

Styling with CSS to format a table so that each cell occupies one row when viewed on narrower

I've come across some HTML that resembles this structure <html><body><table> <thead><tr><th>A</th><th>B</th><th>C</th><th>D</th><th>E</th></tr></thead ...

Learn the method of exhibiting array elements in a dropdown menu with React JS

I am struggling to display all 12 months in a dropdown using React JS. I have written the code below and used moment.js to fetch the months, which I can see in the console but they are not showing up in my dropdown menu. I tried to use .map() to display t ...

Learning to integrate AngularJS with Web API responses can greatly enhance the functionality and user

I am currently attempting to establish a connection with MongoDB using a Web API. I have been following the instructions outlined in the guide found at I am feeling confused when it comes to step 3, Building Angular JS MVC Pattern. My question is: Where ...

What is the most effective way to add HTML from a dynamically loaded document using AJAX?

I am attempting to attach the information from a .html file to the body of my main webpage. Essentially, I am striving to create a reusable section of html that can be loaded into any page with a basic JavaScript function. Below is the content of my navig ...

express middleware is not compatible with prototype functions

I've encountered a perplexing issue while working with the node.js express framework. Let's say I have a file called test.js containing the following code: function a(){ } a.prototype.b = function(){ this.c("asdsad"); } a.prototype.c = f ...

Can a dynamic component be assigned to the <Route> element in react-router-dom?

Exploring the concept of dynamically picking and rendering components: import CompA from './CompA'; import CompB from './CompB'; var componentSet = { 'compa': CompA, 'compb': CompB } var type = 'compa&apo ...

Having trouble with the JQuery scrollTop animation? Getting the error message "Cannot read property 'top' of undefined"?

I am having trouble with my jquery animation scrollTop function. Whenever I click on <a>, it takes me to the anchor without any animation. Can someone please provide a solution for this issue? Upon running the webpage, I encountered an error message ...

Tips for aligning the navigation bar in the center

I recently came across a simple tutorial on w3schools (article) for creating a responsive menu. However, I've been struggling to center it horizontally for the past few days. Here is the HTML code: <ul class="topnav"> <li><a href=" ...

The battle of line-height versus padding for achieving vertical centering with one-lined text

One-lined text can be vertically centered using either the line-height property or by adding padding-top and padding-bottom. What are the advantages and disadvantages of each method? body { font-size: 12px; font-family: ...

The screen is cloaked in a dark veil, rendering it completely inaccessible with no clickable

Utilizing Bootstraps modals, here is my current layout. Within the site's header, there exists a "settings" button that triggers a modal containing various options. These options are not tied to the question at hand. The button responsible for displ ...

The right alignment for ul and li styles is recommended for a cleaner appearance

Here is the fiddle provided below: http://jsfiddle.net/Fx9rA/ <div id="wrap"> <ul id="accordion"> <li> <h2 id="first">CMT</h2> <div class="content"> ...

Using Jquery to toggle the visibility of div elements with the same structure, but ensuring only one is

Many people have posed this question. I am attempting to create a functionality where a div can expand and collapse using a +/- button. I have 5 divs with class=="expanderContent". When the function below is triggered by a click, all 5 items expand or coll ...

Unlocking the AngularJS variable within the template script

My controller code: $scope.totals = totals; In the template, I am able to successfully inject HTML using this code: {{totals}} However, my goal is to access the totals variable in a script within the template. Here's what I attempted: <script& ...

Updating divs automatically using Ajax without refreshing the page is not functioning as intended

I'm having trouble understanding why this isn't functioning properly. My goal is to have the data from load.php displayed in the div sample. However, if the code is updated (for example, when pulling information from a database), I want only the ...

What is the best way to ensure that the checkbox is not affected when you click on the area?

If the user interacts with the checkbox, I don't want the handleClick function to execute. Is there a way to exclude it or prevent the click event from triggering? <div ... onClick={this.handleClick}> <div> some content here < ...