Simple AngularJS Form is undefined in Scope

前端 未结 7 1822
独厮守ぢ
独厮守ぢ 2020-12-13 03:33

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

7条回答
  •  春和景丽
    2020-12-13 04:16

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

提交回复
热议问题