0

I have started using AngularJs and I need some help with controller model data sharing.

I have this html template:

<input ng-model="form.search">

I know that you can pass it with a function like FormCtrl.data(form.search). However I would like to know if there are other ways getting model data in controller.

5
  • 2
    Any thing you can to the scope is available to both view and controller. Scope is the glue that makes it happen. Read more about scope Commented Jan 21, 2014 at 9:29
  • Well I tried accessing the value from $scope.search in controller. But it is undefined. Commented Jan 21, 2014 at 9:32
  • what about $scope.form.search? Commented Jan 21, 2014 at 9:36
  • console.log($scope.form) = undefined Commented Jan 21, 2014 at 9:40
  • Looks like was not able to access the $scope from controller, because I was using the ng-boostrap modal. And I was assuming that ModalInstanceCtrl has the access to $scope whatever is on the modal form. But it looks like I need to apply other controller on the form to access the the $scope. Thanks guys. Commented Jan 21, 2014 at 10:18

1 Answer 1

1

You can access any model data in your Controller, e.g. console.log($scope.form.search) will have it printed. You may also want to ng-init the the form at the beginning of your controller code: $scope.form = {}, before console.log($scope.form.search) is invoked.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.