1

I have next Angular JS controllers structure:

<div ng-controller="MainController">
   <div ng-controller="mainCtrlTst">
      // here is loaded HTML file  
   </div>
</div>

HTML file:

<div ng-controller="MainController">
  <input ng-model="formData.map" value="">
</div>

For default formData.map containts address "USA, New York" I have method Save() in MainController, but when I call this method I get:

console.log(formData.map); // undefined

How I can get value formData.map from input?

1
  • 1
    Is MainController nested within itself? Commented Sep 1, 2015 at 15:44

2 Answers 2

1

You should declare your model in controller like

$scope.formData = {
    map: ''
};

And then use it in the view.

And then check in the save method by following code

console.log($scope.formData.map);

Hope you will not get undefined.

Sign up to request clarification or add additional context in comments.

2 Comments

I have declared $scope.formData
Still you get undefined when use console.log($scope.formData.map);
0

Try the following in MainController:

console.log($scope.formData.map);

To be more precise, in your save() function inside the controller do as follows:

$scope.save = function(){
    console.log($scope.formData.map);
}

To know more about $scope, visit : https://docs.angularjs.org/guide/scope

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.