title: AngularJS insert data twice to database
body: <p>I am trying to insert data to database through angularJS but the data inserted twice.. I have tried to use ngRoute but still I face the same problem.</p>
  
  <p>app.js</p>
  
  <pre><code> var app = angular.module("addDepApp", []);
   app.controller('insertDepCtl', function($scope, $http) {
  
  var isSend = false;
  $scope.$on('newuser', function(event, data){
      load(true);
  
  });
  
  
  var load = function(isEvent){
  
      if($scope.$parent.newuser != null){
          isSend = true;
      }
  };
  load();
  
  $scope.insertDepartment = function () {
      console.log("called insertDepartment");
      if (isSend == true){
          $scope.newuserSend = {'org_id': $scope.$parent.newuser.org_id, 'dep_name': $scope.department};
          $http.post("http://192.168.1.12:8888/XXXX/XXX/insertDep.php/",$scope.newuserSend)
  
      }
  
  }
  
  });
  </code></pre>
  
  <p>add.html</p>
  
  <pre><code>  &lt;body ng-app="addDepApp"&gt;
    &lt;div class="12u$" ng-controller="insertDepCtl"&gt;
    &lt;input type="button" value="تسجيل" class="special" id="signup" ng-click="insertDepartment()"/&gt;
    &lt;/div&gt;
    &lt;/body&gt;
  </code></pre>