I\'m starting to play around with AngularJS forms in jsfiddle and I\'ve come across a problem already where a very simple form example is not working as expected. All I have
In my case I used ng-include
to generate a sub scope, so within current scope the property is undefined
, to be safe and prevent sub-scope issue, we should use reversed variable to name the form just like form.theForm
.
But make sure that you've declared this form name in your controller in advance.
app.controller('MainCtrl', ['$scope', function($scope) {
$scope.model = { name: 'Model Name' };
//You have to declare here, else it will trigger undefined error still.
$scope.form = {
theForm: {}
};
$scope.reset = function(){
$scope.form.theForm.$setPristine();
}
}]);