0

I am using a controller like this

  app.controller('EmployeeCrtl', ['$http', '$scope', function($http, $scope) {
    $http.get('/Data/EmployeeDetails.json').success(function(data) {
      $scope.EmployeeData = data;
    }).error(function() {
      alert('error');
    });

    //check employee details value
    $scope.insertEmployeeDetails = function(emp) {
      debugger;
      if (emp.EmployeeName !== '' && emp.Designation !== '' && emp.Email !== '' && emp.Address !== '' && emp.PhoneNumber !== '') {
        if (emp.EmployeeName !== undefined && emp.Designation !== undefined && emp.Email !== undefined && emp.Address !== undefined && emp.PhoneNumber !== undefined) {
          debugger;
          $scope.EmployeeData.push(emp);
          this.emp = {};
        }
      }
    }
  }]);

and i have a directive like this

 app.directive('addEmployee', function() {
   return {
     restrict: 'A',
     templateUrl: '/Template/AddEmployee.html',
     link: function(scope, elem, attr, ctrl) {
       debugger;
     },
     controller: 'EmployeeCrtl',
     scope: {
       insertEmployeeDetails: "&",
       EmployeeData: "="
     }
   };
 });

Now what i am trying to do is, when i call the insertEmployeeDetails function i push the EmployeeData with the new data, but in this i get an error like this console error can anyone help me on how to remove this error, i actually want the data which is added in the EmployeeData property to be bound in the table which i use

CozyAzure
  • 8,280
  • 7
  • 34
  • 52
Lijin Durairaj
  • 653
  • 1
  • 6
  • 9
  • If EmployeeCrtl is the controller for your directive then EmployeeData and insertEmployeeDetails are already in scope for the directive. Don't pass them in as if they are attributes of the directive. – jbrown Jan 11 '17 at 14:03
  • you mean to say that i dont have to use controller: 'EmployeeCrtl', in my directive??? then how will the directive find the directive? – Lijin Durairaj Jan 11 '17 at 14:06
  • you are right removing it worked for me, but my question is how do the directive come to know about the controller and its scope – Lijin Durairaj Jan 11 '17 at 14:08
  • Its either/or. If you assign a controller then your directive will work with the scope of the controller. If you pass variables into your directive's isolate scope as attributes then it will use those variables. – jbrown Jan 11 '17 at 14:10

0 Answers0