0

I am not able to get alert for delete function even if i had done right procedure so please help me for the same.Thanks in advance for solving my problem I am not able to get alert for delete function even if i had done right procedure so please help me for the same.Thanks in advance for solving my problem

<html ng-app="crudApp">
    <head>
        <meta charset="UTF-8">
        <title>Angular js</title>
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    </head>

    <body>
        <form name="addForm"  ng-submit="Add" ng-controller="employeecontroller">
            First Name: <input type="text" ng-model="firstname"><br/><br/>
           Last Name: <input type="text" ng-model="lastname"><br/><br/>
            <input type="submit" name="btnInsert" value="Insert" ng-click='insertData()'/>
        </form>

        <div ng-controller="DbController">
            <table border="1">
                <tr>
                    <th>Firstname</th>
                    <th>Lastname</th>
                </tr> 
                <tr ng-repeat="detail in details">
                    <td>{{detail.firstname}}</td>
                    <td>{{detail.lastname}}</td>
                    <td><input type="button" value="Delete"  ng-click="deleteInfo()"/></td>
                </tr>
            </table>

        </div>
        <script>

            function employeecontroller($scope, $http) {
                $scope.insertData = function () {
                    $http.post("insert.php", {
                        'firstname': $scope.firstname,
                        'lastname': $scope.lastname,
                    }).success(function (data, status, headers, config) {
                        console.log("Data Inserted Successfully");
                    });
                }
            }

            var crudApp = angular.module('crudApp', []);
            crudApp.controller("DbController", ['$scope', '$http', function ($scope, $http) {
                    // Sending request to EmpDetails.php files
                    getInfo();
                    function getInfo() {
                        $http.post('select.php').success(function (data) {
                            // Stored the returned data into scope

                            $scope.details = data;

                            console.log(data);
                        });
                    }
                }]);

            function DbController($scope,$http) {

                $scope.deleteInfo = function () {
                    alert("hello");

                }
            }

        </script>

    </body>

</html>
2
  • Did you managed to work with the employeecontroller? it looks as if it's not registered to your app. no errors? Commented Aug 1, 2016 at 8:08
  • No need to repeat yourself... Commented Aug 1, 2016 at 8:20

1 Answer 1

1

Each controller should be registered as part of your Angular app. You have registered DbController but then created a separate function called DbController that Angular is unaware of. Try moving your delete function to the registered controller. Like this:

 crudApp.controller("DbController", ['$scope', '$http', function ($scope, $http) {
                    // Sending request to EmpDetails.php files
                    getInfo();
                    function getInfo() {
                        $http.post('select.php').success(function (data) {
                            // Stored the returned data into scope

                            $scope.details = data;

                            console.log(data);
                        });
                    }

                   $scope.deleteInfo = function () {
                    alert("hello");
                    }
                 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.