在angularJS中无法在Directive中使用双绑定

时间:2017-01-11 13:37:38

标签: angularjs angularjs-scope directive

我正在使用像这样的控制器

  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 = {};
        }
      }
    }
  }]);

我有一个像这样的指令

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

现在我要做的是,当我调用 insertEmployeeDetails 函数时,我用新数据推送 EmployeeData ,但在此我得到一个像这样的错误 console error 任何人都可以帮我解决如何删除此错误,我实际上希望 EmployeeData 属性中添加的数据绑定在我使用的表中

0 个答案:

没有答案