Search code examples
javascriptangularjsangular-ui-bootstrapangular-controller

Scope value is Undefined within $modal popup function as an object


I've the scenario where I'm using $uibModal popup to add a new record, where I'm passing the scope object into the function to get it saved, but I'm getting the result as 'undefined' and my code is below along with the [plunker] (http://plnkr.co/edit/WXKCyzlfJFCA3FB7S2pa?p=preview) link.

  $scope.userList=[];
  $scope.addUser = function(){
    $uibModal.open({
      templateUrl: 'userData.html',
      controller: 'MainCtrl'
    });
  };
  $scope.addNewUser=function(user){
    console.log(user);
    $scope.userList.push({
      'id': user.id,
      'name': user.name,
      'age': user.age,
      'gender': user.gender
    });
    $scope.clearUserArea(user);
  };
  $scope.clearUserArea = function(user){
    console.log(user);
    user.id='';
    user.name='';
    user.age='';
    user.gender='';
  };

Please let me know where I'm wrong with this code. And also please refer my plunker link for further code on this.


Solution

  • You had misspelled in ng-modal . it should be ng-model instead of ng-modal.