Search code examples
javascriptmeanjs

MEAN.js - what does this piece of javascript mean?


Good sirs: in the boilerplate MEAN.js code, I see this...

<form name="articleForm" data-ng-submit="update(articleForm.$valid)" >

yet the controller says this...

$scope.update = function() {
    var car = $scope.car;
    car.$update(function() {
        $location.path('cars/' + car._id);
    }, function(errorResponse) {
        $scope.error = errorResponse.data.message;
    });
};

So what is happening with articleForm.$valid?

I assume it is a boolean, but it looks like $scope.update doesn't have an argument to access that boolean. and simply passing FALSE to a javascript function normally doesn't stop that function from executing...


Solution

  • The form.$valid field indicates if all the fields of the form contain valid input.

    In this case the update function does not take any parameters so sending the form.$valid to it does not change anything.