AngularJs can't access form object in controller ($scope)

Just for those who are not using $scope, but rather this, in their controller, you'll have to add the controller alias preceding the name of the form. For example:

<div ng-controller="ClientsController as clients">
  <form name="clients.something">
  </form>
</div>

and then on the controller:

app.controller('ClientsController', function() {
  // setting $setPristine()
  this.something.$setPristine();
};

Hope it also contributes to the overall set of answers.


The normal way if ng-controller is a parent of the form element: please remove this line:

$scope.form = {};

If angular sets the form to your controllers $scope you overwrite it with an empty object.


As the OP stated that is not the case here. He is using $modal.open, so the controller is not the parent of the form. I don't know a nice solution. But this problem can be hacked:

<form name="form" ng-init="setFormScope(this)">
...

and in your controller:

$scope.setFormScope= function(scope){
   this.formScope = scope;
}

and later in your update function:

$scope.update = function () {
    console.log(this.formScope.form); 

};