0
<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);
1
  • How is not working? It's not printing it? It's showing an error? Also, which browser are you using? Console.log doesn't work on IE <9. Commented May 3, 2016 at 6:50

3 Answers 3

2

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>
Sign up to request clarification or add additional context in comments.

2 Comments

I don't think you need the var in var $scope.form = ...
You are right. I was not sure about this but now i changed it
0

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);

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.