How to manually trigger AngularJS validation from a button outside of the form tags?

后端 未结 6 1273
滥情空心
滥情空心 2020-12-25 11:45

Given this code:

Header inputs:
6条回答
  •  梦谈多话
    2020-12-25 12:44

    Give your form a name:

    So you can access your form validation status on your scope.

    app.controller('MyCtrl', function($scope) {
        $scope.myForm.$valid // form valid or not
        $scope.myForm.myInput // input valid or not
        // do something with myForm, e.g. display a message manually
    })
    

    angular doc

    There is no way to trigger browser form behavior outside of a form. You have to do this manually.

提交回复
热议问题