Divide the text box using Angular.js

Greetings everyone,

Currently, I am working on the angular-seed project. I came across a jsfiddle showcasing a TODO example and I want to include another <input type-"text">

Is there a method to split <input type-"text"> to display two <input type-"text"> in a single row? My concept is similar to this jsfiddle created with jQuery, where the combined string should be added to the <li> element

Thank you very much,

app.html

 <div ng-controller="MyCtrl">
        <input type="text" ng-model="enteredName" />
        <button ng-click="addName()">Add</button>
        <ul>
            <li ng-repeat="name in names">
                {{ name }}
                <button ng-click="removeName(name)">&times;</button>
            </li>
        </ul>
    </div>

app.js

var myApp = angular.module('myApp',[]);

function MyCtrl($scope) {
    $scope.names = ['batman', 'grumpy', 'yulu'];

    $scope.addName = function(){
        $scope.names.unshift($scope.enteredName);   
    }

    $scope.removeName = function(name) {
        var i = $scope.names.indexOf(name);
        $scope.names.splice(i, 1);
    }
}

Answer №1

To create the appearance of two inputs, you need to actually use 2 inputs and modify your array of strings to an array of objects with minimal changes in the view.

 $scope.names = [{first: 'bat',last: 'man'}];

View

<input type="text" ng-model="enteredName.first" />
<input type="text" ng-model="enteredName.last" />
<button ng-click="addName()">Add</button>
<ul>
   <li ng-repeat="name in names">
      First: {{ name.first }} Last: {{ name.last }}
      <button ng-click="removeName(name)">&times;</button>
   </li>
</ul>

DEMO

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

Utilizing HTML5 geolocation to assign latitude and longitude values to a PHP variable when clicked

Can we retrieve the latitude and longitude of a user by using HTML5 geolocation when they click a button, then pass these values to PHP variables on a new page? For example, if a user is on index.php, where the HTML5 geolocation code is located, and they ...

Toggle between pausing and running CSS animations with this handy button!

My awesome graphic animation is in CSS and SVG format. I've been struggling to add a play/pause button to control the animation on click. Here is what I have so far: .animation1 { --animation-delay: 0.1s; animation: ani_keyframes 1 ...

Duplicate multiple "li" elements using jQuery and place them in a designated position within the ul element, rather than at the end

I am currently working on developing a dynamic pagination bar. This pagination bar will dynamically clone the "li" elements based on a number received from an external webservice. Here is the structure of my pagination element: <ul class="pagination"& ...

Find a pair of buttons nested within each other

I need assistance with nesting two buttons inside each other using HTML. Here is what I have attempted: <div id="photoShow" style="width: 190px; height: 212px"> <input type="button" runat="server" id="btn_ShowImage" style =" background-imag ...

Implementing React and Material UI - Customizing Navigation Buttons/Links according to Routes

The following code snippet represents the main entry point of a React app, app.js, which includes the router endpoints. Below the app.js code, you will find the code for a Nav component, which serves as the navigation menu. I am looking to structure this ...

Implementing WordPress pagination with a featured post exclusively on the initial page

I'm working on a layout for posts, where the first page displays a featured post and rows of three columns of posts. First Page |---------------Featured Post---------------| |----Post----| |----Post----| |----Post----| |----Post----| |----Post----| ...

No validation errors are currently being displayed. I am attempting to retrieve the error message when validation fails

My form validation error has suddenly stopped working. It was functioning properly yesterday, so I must have made a mistake somewhere, but I can't seem to pinpoint it. Now, when I attempt to sign up without entering any information, it just redirects ...

style of placing a space between objects

Is there a way to create space between the border (underline hover effect) and have the color of the line be red? a { text-decoration: none } li { display: inline; } li:hover { text-decoration: underline; } <li><a href=""> abc < ...

Equally distributing the space while adjusting the size of the browser window

When adjusting the size of the browser window, I noticed that the space after the element is reduced. I would like to decrease the space equally on both the left and right sides, similar to how it is done on Facebook. Below is the code I have: CSS: body ...

Issue: the size of the requested entity is too large

Encountering an error message while using express: Error: request entity too large at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:16:15) at json (/Users/ ...

Halt the program's process until the ajax request has finished

Struggling with what seems like a common issue of the "Asynchronous Problem" and finding it difficult to find a solution. Currently, I am working on a custom bootstrap form wizard which functions as tabs/slideshow. Each step in the wizard is represented b ...

Latest output is fetched by jQuery from the load() method

I'm encountering an issue with the code present in index.html: $(document).ready(function() { $('#generate').click(function() { //$("#results").empty(); $("#results").html(""); $("#results").load("generate.php"); }); }); In addition ...

Passing information from Vue to a modal

I'm working with 3 components: TaskList, TaskItem, and TaskForm. Within the TaskList component, there is a loop that renders all the data in TaskItem. Each TaskItem has an edit button meant to open a TaskForm modal (using bootstrap) displaying the sp ...

How to break down JSON into individual elements using JavaScript

{ "name": "Sophia", "age": "Unknown", "heroes": ["Batman", "Superman", "Wonder Woman"], "sidekicks": [ { "name": "Robin" }, { "name": "Flash Gordon" }, { "name": "Bucky Barnes" } ...

Using AJAX to make a request in a separate Java application environment with Tomcat

Two of my web applications are built in Java using Spring Security. Each application has its own WAR file and is deployed on a separate context: localhost:8080/my-app1 localhost:8080/my-app2 However, when attempting to make an AJAX call from my-app1 to a ...

How can I use Chart.js to assign a unique color to each x-axis label?

I'm currently using Chart Js to create a chart and I want each label to have a different color instead of all labels having the same color. Is there a way to achieve this using the ticks callback function? scales: { xAxes: [{ ...

What is the most efficient way to remain on the current page after sending a post request and then sending another post request?

For my one-page website project, I am working on a form that allows users to input text and upload files. The desired functionality of the form includes typing text in a textarea, selecting multiple files, uploading them after clicking a button, and then s ...

Unable to display images in CodeIgniter when using the html helper function

As a newcomer to CodeIgniter, I am looking to retrieve data from a MySQL database using CodeIgniter. The data I am working with is an image, and I have organized my application with the following folder structure: 1. ci application controllers views ...

React: The rendering is being blocked by costly computation in useEffect

Whenever a user changes the select option, there is some time-consuming work that needs to be done. I want to display a loading message while this work is being carried out, but unfortunately, it's not functioning as expected. import React, { useState ...

Having trouble with Bootstrap card deck's card heights not aligning?

Struggling to align Bootstrap's card deck vertically? One card with shorter text is causing a mismatch and you're not sure how to fix it. On the same page, you want three cards displayed horizontally on desktop and stacked vertically on mobile. ...