Reputation: 27507
I have a form:
<form ng-submit="submit()">
New Chore: <br>
Name: <input type="text" name="name"><br>
Hours: <input type="text" name="hours"><br>
<input type="submit" id="submit" value="Submit" />
</form>
and in my controller:
$scope.submit = function() {
if ($scope.name) {
alert("here");
$scope.chores.push({name: $scope.name, hours: $scope.hours});
$scope.name = '';
} else {
alert("none");
}
};
But it is always going to the else
statement. How do I grab the name and hours in my form in my controller?
Upvotes: 0
Views: 391
Reputation: 48972
You're not binding your input values to your scope's properties.
Try ng-model:
<form ng-submit="submit()">
New Chore: <br>
Name: <input type="text" name="name" ng-model="name"><br>
Hours: <input type="text" name="hours" ng-model="hours"><br>
<input type="submit" id="submit" value="Submit" />
</form>
Upvotes: 2