Button addition in Angular is malfunctioning

I have a form with add and remove fields implemented using angularjs. It works fine when running outside the div, but when placed inside a div, only the remove function is working. Can you please advise on what might be going wrong?

<body>

<div class="container"> 

        <div class="row">

            <div class="col-md-2 col-sm-2">
                <div class="emp_details"> 
                <h3><span>Anil Kumar K</span></h3>
                <h3><span>IND1469</span></h3>
                <hr></hr>
                <h2><span>Manager</span></h2>
                <h3><span>Vikram Ranade</span></h3>
                </div>
            </div>

    <div class="col-lg-10 col-sm-10">

    <div class="card hovercard">
        <div class="card-background"> 
          
        </div>
      
        <div class="card-info"> <h1><span class="card-title">OBJECTIVES</span></h1>
        </div>
    </div>

    </div>
</div>

...

JavaScript file

var app = angular.module("myapp", []);
  app.controller("ListController", ['$scope', function($scope) {
      $scope.personalDetails = [
          {
              'fname':'Muhammed',
              'lname':'Shanid',
              'email':'<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="97e4fff6f9fef3d7e4ff...     }

          ];

...

CSS file

/* USER PROFILE PAGE */
 .card {

...

Answer №1

If you want to create a new function in your AngularJS application, follow this syntax:

$scope.addNew = function(personalDetails) {
 // Code
}

The above code snippet defines a function named `addNew` that takes an argument called `personalDetails`. When calling the add function in your view, make sure to pass `personalDetails` as an argument.

<form ng-submit="addNew(personalDetails)">

Here is an example of how you can implement this in your AngularJS app:

var app = angular.module("myapp", []);
app.controller("ListController", ['$scope', function($scope) {
  $scope.employeeCount = 4;
  $scope.personalDetails = [{
      'fname': 'Muhammed',
      'lname': 'Shanid',
      'email': 'example@example.com'
    },
    {
      'fname': 'John',
      'lname': 'Abraham',
      'email': 'john@example.com'
    },
    {
      'fname': 'Roy',
      'lname': 'Mathew',
      'email': 'roy@example.com'
    }
  ];

  $scope.addNew = function(personalDetails) {
    $scope.personalDetails.push({
      'fname': personalDetails.fname,
      'lname': personalDetails.lname,
      'email': personalDetails.email,
    });
    $scope.PD = {};
  };

  // Other controller functions defined here

}]);
x
/* Your CSS styles go here */
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="container">

  <!-- Your HTML content goes here -->

</div>

Answer №2

<form ng-submit="addNew()">
In this code snippet, there is a missing argument being passed. However, in the corresponding controller function

$scope.addNew = function(personalDetails){
              $scope.personalDetails.push({ 
                  'fname': personalDetails.fname,
                  'lname': personalDetails.lname,
                  'email': personalDetails.email,
              });
              $scope.PD = {};
          };

The expected parameter is personalDetails, so make sure to update the html as follows

<form ng-submit="addNew(personalDetails)">

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

Issues with the Tumblr platform's back-to-top button functionality

I am quite comfortable with HTML and CSS, but I'm struggling to make the 'back to top' button work on my Tumblr page. Can someone please give me a hand? I've included some JQuery code to make the text fade in and out when scrolling (inf ...

Ensuring AngularJS ui-router/app waits for $http data to avoid Flash of Unstyled Content (FOUC)

My question or situation pertains to the states defined in my AngularJS application. Here is an example of how I have them structured: $stateProvider .state('myApp', { abstract: true, template: '& ...

Do you want your image to appear visually pleasing on all screen sizes?

Currently, I am working on a mobile website and encountering an issue with the image banner. For tablets, it should look like this: However, when viewed on mobile, it needs to appear as follows: This is the code I have implemented so far: <div class ...

Avoiding the opening of a select menu

Is there a way to prevent the dropdown menu from appearing when a select element is clicked in a form? I have attempted two methods but they did not work: $('select').click (function (e) { console.log (e); return false; }); and $(&apo ...

Follow each step to see the final outcome

I have a Step-by-step form that includes a simple calculation. To calculate section 08, I have a function that subtracts liabilities from assets and displays the result as net equity. $(document).ready(function () { // Calculate section 08 ...

From AngularJS, switch your dots to commas for a fresh

As a beginner in angularjs, I am facing an issue with my program which reads prices from a .json file. The prices are all in decimal format with dots instead of commas. I am looking for guidance on creating a directive or another solution to replace the do ...

Containerized chatboxes with improved stability

https://i.sstatic.net/ILwsO.jpg Within the div labeled chatbox-container, there are two chatboxes that have been positioned to float: right with a margin-right: 15px. .chatbox-container { position: fixed; z-index: 1; right: 0; left: 0; ...

The rate of increase decreases as the value approaches its maximum assignment

Visualizing this question requires some pseudo-code, so here it is: Imagine I have two integers - one variable and one constant. int current = 0; static int max = 20 My goal is to add slowly as I approach 20, never actually reaching it. For example, if ...

Use JavaScript to sift through an array and exclusively retrieve items that match a specific value

I am working with an array of objects that contain a phase key, and I want to filter out only the ones that have a specific phase value. Additionally, I need to map some other key/value pairs into the final return. Here is my current code: phaseToBlocks ( ...

Acquiring exclusive files from Laravel 8 storage directory using JavaScript

I find myself in a specific situation: Working with a Laravel 8 application. My users upload STL files, which are stored in the storage/app/users/{userid} directory. These STL files are private and not accessible to everyone as they are not located in the ...

retrieve data from jsp page using ajax request

I've coded this JSP snippet Map<String, Long> map = new HashMap<String, Long>(); map.put("A", 10L); map.put("B", 20L); map.put("C", 30L); JSONObject json = new JSONObject(); json.accumulate ...

Node.js for Streaming Videos

I am currently working on streaming video using node.js and I recently came across this helpful article. The setup works perfectly when streaming from a local source, but now I need to stream the video from a web source. However, my specific requirement i ...

Exploring the power of Jasmine with multiple spy functionalities

I'm currently working on writing unit tests for an Angular application using Jasmine, specifically focusing on testing different scenarios within a function. The main challenge I am facing is structuring the test to accommodate various conditions such ...

Retrieving the default props of a child component in Vue after it has mounted

I'm currently exploring how to access the default properties (props) for a child component. The scenario involves two components, A and B. Component B wraps around component A, which is passed properties. My goal is to determine the default values of ...

Obtaining the most recently inserted ID in Node.js can be achieved by using

Currently in my Nodejs project, I am using the expressjs framework. I am facing an issue where I am trying to retrieve the "last inserted id", but it is showing as "undefined" in the console. How can I successfully get the last inserted id? Below is the ...

The extended interface appears to be lacking the implementation of parent members

I am facing an issue with two interfaces export interface IComponent{ type: ComponentType; name: string; isEnabled:boolean; } export interface IAudioComponent extends IComponent { source: string; volume: number; loop: boolean; ...

How to implement various middlewares in Express.js depending on the current environment using NODE_ENV?

My dilemma involves utilizing two different middlewares based on NODE_ENV: router1 for production and router2 for testing and development environments. I'm currently using the following code snippet: if( process.env.NODE_ENV === 'prod' ) { ...

In Javascript, ensuring a stopping condition for a recursive function that is looping through JSON data

I am having trouble figuring out how to set the break condition for this recursive function. Currently, the function is causing the browser to freeze (seems to be stuck in an endless loop). My goal is to create a series of nested unordered lists based on ...

Unable to successfully transfer a document

I am looking to upload a file onto my server. Here is what I have attempted: <input (change)="uploadImage($event.target)" hidden accept="image/*" #uploadProfileImage type="file"> uploadImage(event) { const profileImage = event.files.item(0); t ...

Discovering the difference between a singular array and an array of arrays

x = [1, 2,3, 5]; y = [1, [2], [3, [[4]]],[5,6]])); I am currently facing a challenge in finding the difference between these two arrays. function findArrayDifference(arr1, arr2) { var tempArr = [], difference = []; for (var i = 0; i < arr1.l ...