1

When a JQuery retrieved value passed to a controller function via ng-click it is undefined

<button ng-click="getDefinition( $('#selection2').val());">Submit</button>

controller:

  $scope.getCriteriaDefinition = function (data_dictionary_id) {

//data_dictionary_id is undefined
}

Any ideas? I thought the value contained within the ng-click attribute gets parsed and then run

FutuToad
  • 2,750
  • 5
  • 36
  • 63
  • Why are you doing that? See http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs-if-i-have-a-jquery-background?rq=1 – Jonathan Wilson Jun 25 '14 at 09:40

1 Answers1

1

Instead of retrieving the value using jquery, you can do it angular like the following.

For now i am assuming $('#selection2') as an input element, it can be select or any form element.

in form:

<div class="holder" ng-controller="formHolder">
    <input type="text" id="selection2" ng-model="inputModel">
    <button ng-click="getDefinition(inputModel)">Submit</button>
</div>

in Controller:

$scope.getCriteriaDefinition = function (data_dictionary_id) {
    //access data_dictionary_id here.
}

in Angular JS the ng-model stores the value, what the element currently holds.As both the button and input are in the same controller, we can access input value in button.

Hope this helps.