locked
$scope.employeeList.employeeId is not getting identified..plz help RRS feed

  • Question

  • User483994611 posted

    I am new to angular js.My objective is to edit row values of a grid on clicking edit button which is present inside the row.

    My prob is $scope.employeeList.employeeId ,$scope.employeeList.employeeName is not getting identified..Please suggest where I am doing wrong

    $scope.editEmployee = function (employee) {

    debugger;


    alert(employee.Id);
    //alert($scope.employeeList.employeeId);
    $scope.employeeList.employeeId = employee.Id;
    $scope.employeeList.employeeName = employee.name;
    $scope.employeeList.employeeEmail = employee.email;
    $scope.employeeLists.employeeAge = employee.Age;
    $scope.Action = "Update";
    $scope.divEmployee = true;
    }

    The edit div looks like:-

    <div ng-show="divEmployee">
    <p class="divHead">{{Action}} Employee</p>
    <table>
    <tr>
    <td><b>Id</b></td>
    <td>
    <input type="text" disabled="disabled" data-ng-model="employeeList.employeeId" />
    @*<input type="text" disabled="disabled" ng-model="employeeId" />*@
    </td>
    </tr>
    <tr>
    <td><b>Name</b></td>
    <td>
    @*<input type="text" ng-model="employeeName" />*@
    <input type="text" data-ng-model="employeeList.employeeName" />
    </td>
    </tr>
    <tr>
    <td><b>Email</b></td>
    <td>
    @*<input type="text" ng-model="employeeEmail" />*@
    <input type="text" data-ng-model="employeeList.employeeEmail" />
    </td>
    </tr>
    <tr>
    <td><b>Age</b></td>
    <td>
    @*<input type="text" ng-model="employeeAge" />*@
    <input type="text" data-ng-model="employeeList.employeeAge" />
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <input type="button" class="btnAdd" value="Save" ng-click="AddUpdateEmployee()" />
    </td>
    </tr>
    </table>
    </div>

    My controler looks like

    public JsonResult getAll()
    {
    using (SampleDBEntities dataContext = new SampleDBEntities())
    {
    var employeeList = dataContext.Employees.ToList();
    return Json(employeeList, JsonRequestBehavior.AllowGet);
    }
    }

    Monday, June 6, 2016 6:57 AM

Answers

  • User-1672470423 posted

    Can you please try by adding line as shown in bold and check ?

    alert(employee.Id);
    //alert($scope.employeeList.employeeId);
    $scope.employeeList = {};
    $scope.employeeList.employeeId = employee.Id;
    $scope.employeeList.employeeName = employee.name;
    $scope.employeeList.employeeEmail = employee.email;
    $scope.employeeLists.employeeAge = employee.Age;
    $scope.Action = "Update";
    $scope.divEmployee = true;
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 6, 2016 1:39 PM
  • User61956409 posted

    Hi suvo,

    My prob is $scope.employeeList.employeeId ,$scope.employeeList.employeeName is not getting identified..Please suggest where I am doing wrong

    As Sumit.Pokhriyal said, you could try to initiate employeeList before you specify the value of properties. The following sample code works fine, you could refer to it.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
        <script>
            var app = angular.module('myapp', []);
    
            app.controller('MyCtrl', function ($scope) {
    
                $scope.editEmployee = function (employee) {
                    //alert(employee.id);
    
                    $scope.employeeList = {};
    
                    $scope.employeeList.employeeId = employee.Id;
                    $scope.employeeList.employeeName = employee.name;
                    $scope.employeeList.employeeEmail = employee.email;
                    $scope.employeeLists.employeeAge = employee.Age;
                }
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div ng-app="myapp" ng-controller="MyCtrl" ng-init="employee = { id: 1, name: 'jack', email: 'xxx@xxx.com', Age: 28 };">
                {{employee.name}}
                <br />
                <input id="btnedit" type="button" value="Edit" ng-click="editEmployee(employee)" />
                <br />
                {{employeeList.employeeName}}
                <br />
                {{employeeList.employeeEmail}}
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 7, 2016 6:09 AM

All replies

  • User-1672470423 posted

    Can you please try by adding line as shown in bold and check ?

    alert(employee.Id);
    //alert($scope.employeeList.employeeId);
    $scope.employeeList = {};
    $scope.employeeList.employeeId = employee.Id;
    $scope.employeeList.employeeName = employee.name;
    $scope.employeeList.employeeEmail = employee.email;
    $scope.employeeLists.employeeAge = employee.Age;
    $scope.Action = "Update";
    $scope.divEmployee = true;
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 6, 2016 1:39 PM
  • User61956409 posted

    Hi suvo,

    My prob is $scope.employeeList.employeeId ,$scope.employeeList.employeeName is not getting identified..Please suggest where I am doing wrong

    As Sumit.Pokhriyal said, you could try to initiate employeeList before you specify the value of properties. The following sample code works fine, you could refer to it.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
        <script>
            var app = angular.module('myapp', []);
    
            app.controller('MyCtrl', function ($scope) {
    
                $scope.editEmployee = function (employee) {
                    //alert(employee.id);
    
                    $scope.employeeList = {};
    
                    $scope.employeeList.employeeId = employee.Id;
                    $scope.employeeList.employeeName = employee.name;
                    $scope.employeeList.employeeEmail = employee.email;
                    $scope.employeeLists.employeeAge = employee.Age;
                }
            });
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div ng-app="myapp" ng-controller="MyCtrl" ng-init="employee = { id: 1, name: 'jack', email: 'xxx@xxx.com', Age: 28 };">
                {{employee.name}}
                <br />
                <input id="btnedit" type="button" value="Edit" ng-click="editEmployee(employee)" />
                <br />
                {{employeeList.employeeName}}
                <br />
                {{employeeList.employeeEmail}}
            </div>
        </form>
    </body>
    </html>
    

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 7, 2016 6:09 AM