The values are failing to transfer to the table after submitting the information on the form

I'm experiencing issues with my code as some parts are not functioning correctly. While the HTML and CSS sections are working fine, the problem lies in the AngularJS part. When I input data into the form above, I need the employee details to be sent to the table below. Can you help me resolve this issue?

Below are the snippets of my HTML, CSS, and AngularJS code.

var app = angular.module("myapp", []);
app.controller("CRUDoperation", function ($scope) {
    $scope.Emplist = [];
    $scope.AddData = function () {

        var emp = {
            Id: $scope.Emplist.length + 1,
            Name: $scope.Name,
            Salary: $scope.Salary
        };

        $scope.Emplist.push(emp);
        ClearModel();
    };
});

function ClearModel() {
    $scope.Id = 0;
    $scope.Name = '';
    $scope.Salary = 0;
};

$scope.DeleteData = function (emp) {
    var index = $scope.Emplist.indexOf(emp);
    $scope.Emplist.splice(index, 1);
};

$scope.BindSelectedData = function (emp) {
    $scope.Id = emp.Id;
    $scope.Name = emp.Name;
    $scope.Salary = emp.Salary;
};

$scope.UpdateData = function () {
    $.grep($scope.Emplist, function (e) {
        if (e.Id == $scope.Id) {
            e.Name = $scope.Name;
            e.Salary = $scope.Salary;
        }
    })
};
body {
    background-image: url("back.jpg");
}

h1 {
    text-align: center;
    color: Crimson;
}

#save {
    position: absolute;
    left: 400px;
    top: 240px;
    width: 150px;
    height: 40px;
    color: white;
    background-color: pink;
    font-size: 18px;
}

#save:hover {
    color: black;
    background-color: Magenta;
    cursor: pointer;
}

#update:hover {
    color: black;
    background-color: SaddleBrown;
    cursor: pointer;
}

#update {
    position: absolute;
    left: 230px;
    top: 240px;
    width: 150px;
    height: 40px;
    color: white;
    background-color: Peru;
    font-size: 18px;
}

#del {
    width: 110px;
    height: 35px;
    color: white;
    background-color: SeaGreen;
    font-size: 18px;
}

#del:hover {
    color: black;
    background-color: OrangeRed;
    cursor: pointer;
}

#table1 {
    position: absolute;
    top: 300px;
    left: 0px;
    background-color: gray;
}

#table1:hover {
    cursor: copy;
}

input[type=text] {
    position: absolute;
    top: 130px;
    left: 150px;
    width: 400px;
    height: 35px;
}

input[type=number] {
    position: absolute;
    top: 180px;
    left: 150px;
    width: 400px;
    height: 35px;
}

#hidden {
    position: absolute;
    top: 80px;
    left: 150px;
    width: 400px;
    height: 35px;
    background-color: gray:
}

#hidden:hover {
    cursor: not-allowed;
}

span {
    position: absolute;
    top: 90px;
    font-size: 25px;
}

span1 {
    position: absolute;
    top: 135px;
    font-size: 25px;
}

span2 {
    position: absolute;
    top: 185px;
    font-size: 25px;
}
<!DOCTYPE html>
<<!DOCTYPE html>
    <html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <meta charset="UTF-8">
        <title>Angular Web App</title>
    </head>

    <body>
        <h1>Employee Details</h1>
        <div ng-app="myapp" ng-controller="CRUDoperation"></div>
        <div class id="center">
            <table>
                <tr>
                    <td><span>ID</span></td>
                    <td><input type="text" id="hidden" disabled="disabled" placeholder="Auto Filled" ng-model="Id"></td>
                </tr>
                <tr>
                    <td>
                        <span1>Name</span1>
                    </td>
                    <td><input type="text" placeholder="Enter Employee Name here" ng-model="Name"></td>
                </tr>
                <tr>
                    <td>
                        <span2>Salary</span2>
                    </td>
                    <td><input type="number" placeholder="Enter Salary Amount here" ng-model="Salary"></td>
                </tr>
                <tr>
                    <td><input type="button" id=save ng-click="AddData()" value="Save Data"> </td>
                </tr>
                <tr>
                    <td><input type="button" id=update ng-click="UpdateData()" value="Update Data"> </td>
                </tr>
            </table>
            <table border="2" id="table1" style="width:550px;">
                <thead>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Salary</th>
                </thead>
                <tr ng-click="BindSelectedData(Emp)" ng-repeat="Emp in Emplist">
                    <td>{{emp.Id}}</td>
                    <td>{{emp.Name}}</td>
                    <td>{{emp.Salary}}</td>
                    <td><input type="button" ng-click="DeleteData(Emp)" id=del value="Delete"></td>
                </tr>
            </table>
    </body>
    </html>

Answer №1

Angular follows camelCase and interpolation conventions. Therefore, instead of using ng-thing, you should use ngThing, and remember to include parentheses and brackets around them. For example:

[(ngModel)]="blahblah"

[(ngRepeat)]="blahblah"

[(ngClick)]="blahblah"

Furthermore, be cautious as there are two instances of <!DOCTYPE>. This duplication may lead to issues in your code.

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

Clickable label for checkbox in Android browser is unresponsive

I've been experimenting with creating a responsive CSS menu using the checkbox hack Here's the HTML: <input type="checkbox" id="button" /> <label for="button" onclick>click / touch</label> <div> Change my color! </d ...

Adjusting the alignment of Bootstrap navbar

I'm new to CSS and I want to center the brand logo and links in the navbar. HTML <nav class="navbar navbar-expand-md center"> <a class="navbar-brand" href="http://www.dimsum.dk" target="_blank" ...

Opting for PHP over JSON in a jQuery live search code

Is it possible to modify my jQuery Google Instant style search script to pull content from a PHP script instead of using the BingAPI? Below is the current code being used: $(document).ready(function(){ $("#search").keyup(function(){ var searc ...

The issues of cross-origin domains arise when utilizing iframes with src links originating from the server side

Encountering a cross-origin domain issue, receiving the following error while working with an iframe: candidateInterviewCtrl.js:39 Uncaught SecurityError: Blocked a frame with origin "http://localhost:9000" from accessing a frame with origin "http://local ...

What is preventing me from retrieving the value of $accept_request_id?

<form method="post> <button input type="submit" id="click" class="btn btn-info " name="<?php echo$accept_request_id; ?>"></button> </form> What is preventing me from accessing the value of $accept_request_id? The code I ...

What could be causing my HTML form elements to shift position when I click on them in Internet Explorer 8?

I'm facing an issue with my HTML form that has multiple input fields (text and select types) arranged in pairs on each row. Surprisingly, everything works fine in all browsers, including IE7. However, when it comes to IE8, I encounter a peculiar probl ...

Use ajax to load a webpage into a specific div, then reload the same div after submitting

I have a webpage that includes hyperlinks and a content area with an id of "contentarea" where the results from these hyperlinks are displayed. When a user clicks on the "Search" link, the page search.jsp loads, which contains a submit button and a form ...

Discovering a class within a div element using Selenium

Currently, I am attempting to utilize Selenium in Python to locate and click on the 'X' button. This action will redirect me to the next page where I can extract some crucial information. However, I am encountering difficulties in finding the ele ...

What's the deal with Angular's factory pattern?

Is it possible to implement a true Factory pattern in JavaScript and Angular where there is no need to constantly provide the "typeName" parameter? The transition from C# to Java reference types with Angular has been quite challenging for me, and I would ...

Sticky element on the left side vanishes while scrolling towards the right

My goal is to design a webpage with five distinct regions, out of which three are meant to be sticky. However, while implementing this feature, I encountered an issue - when the user scrolls to the right beyond the viewport width, the left sticky elements ...

When outputting HTML, make sure to use an if statement

Looking to dynamically generate select options without using if statements. Instead of string manipulation, I want a cleaner solution. <select name="test"> <option disabled selected> -- Select an industry -- </option> <?php ...

The ValidationEngine fails to validate a dynamically generated form

After dynamically creating a form, the validationEngine stops working. $(window).load(function($) { var form = document.createElement('form'); form.setAttribute('id', 'xform'); var lbl_usr = do ...

Tips for making your inner content as wide as possible

I'm currently working on developing collapsible tables, where an outer and inner table are displayed for every row that is clicked. This is the code I have implemented: HTML: <table class="table outerTbl mb-0"> <thead> <t ...

Display a single image on the tablet and a distinct image on the computer

Currently, I am encountering an issue with my webpage located at . The problem lies in the right upper corner where a ribbon is located. However, when viewing the page on a tablet, the ribbon overlaps with my menu. To resolve this, I thought about displa ...

Locate specific phrases within the text and conceal the corresponding lines

I have a JavaScript function that loops through each line. I want it to search for specific text on each line and hide the entire line if it contains that text. For example: <input id="search" type="button" value="Run" /> <textarea id ...

Issue encountered while trying to pass updated values from an Angular UI modal back to the parent screen

When I click on an item in a list, I want to open an angularUI modal. I can successfully load the modal, make changes, and return to the main screen. However, I am struggling with updating the list on the main screen after closing the modal. I've trie ...

How can I translate an entity diagram (.vpp) into a database or text file using Java?

Is there a way in Java to convert an entity diagram into a database table or text file? If so, how can this be accomplished? Is it possible to export the .vpp file to an HTML file and then convert the HTML file into a text file? Any help would be greatly ...

The JQuery mouseover and mouseout functionality for CSS is not functioning properly

Struggling to create an expanding navigation bar using CSS. Managed to implement it, but ran into issues when it kept resetting after navigating to a new page. Resorted to using jQuery to resolve the problem by utilizing mouse enter and mouse leave events. ...

Tips for inserting a rotated image using CSS

I've created the following code snippet. However, there is a new requirement stating that the image needs to be rotated by 180 degrees. How can I make this happen? #cell { background-image: url("../images/logo.PNG"); background-attachment: fixed; b ...

Ways to prompt the numerical keyboard on mobile devices using the input type "text" attribute

When using the input type "number," the default keyboard on mobile is numeric. However, I prefer to use type "text" because I am entering a PIN which may begin with 0 and requires additional attributes such as minlength, maxlength, and pattern. I am curio ...