Reputation: 41
<form name="vm.form">
<input name="name">
<input type="password" name="password">
</form>
How can I access input value with vm.form?
I've tried this, but it's not working:
console.log(vm.form.name)
Can I do it like this? Or are there any other easy way?
I'm posting data to other server like this:
$http.post('/someUrl', vm.form, config).then(successCallback, errorCallback);
Upvotes: 0
Views: 2440
Reputation: 192
You can try this
<form name="vm.form" ng-submit="YourServerSideFun(myForm)">
<input name="name" ng-model="myForm.name">
<input type="password" name="password" ng-model="myForm.password">
<input type="submit"/>
</form>
Pass your myForm as Object.
Upvotes: 0
Reputation: 314
You can try this: in your HTML
<form name="vm.form" ng-model="myForm">
<input name="name" ng-model="myForm.name">
<input type="password" name="password" ng-model="myForm.password">
</form>
and in your script use "myForm"
$http.post('/someUrl', $scope.myForm, config).then(successCallback, errorCallback);
Upvotes: 0
Reputation: 163
You can create an object in your controller
$scope.form = {name:"", password=""}
and then you can access it in your html via the ng-model
<form>
<input ng-model="form.name">
<input type="password" ng-model="form.password">
</form>
Upvotes: 2