nick_1002 nick_1002 - 4 months ago 43
Javascript Question

Ionic 1: Ionic list printing selected item value

I've just started out using Ionic, I am trying to print the value of the selected list Item

{{ item.value }}
, however can't find any documentation that suggests how to do this.

Possibly an
ng-click="myFunction()"
would work here, but I am stuck as to where to start. I have it working with the Ionic Radio buttons. But I want the list to re-direct to another page on click, but still hold this value in the main controller.

Here is the Codepen attempt.

Thank you.

Answer

Well, at first ng-click="do" will do absolutely nothing. It should be ng-click="do()", and of course, you have to have a function called do in your controller to perform an action.

The 2nd. problem is: you're inside ngRepeat, it creates a child $scope, so you have to use the Dot Rule:

$scope.model = {};

Then, you can do it:

ng-click="model.itemValue = item"

Check the forked DEMO