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.
我刚刚开始使用Ionic,我正在尝试打印所选列表Item {{item.value}}的值,但是找不到任何建议如何执行此操作的文档。
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.
可能是ng-click =“myFunction()”可以在这里工作,但我不知道从哪里开始。我让它与Ionic Radio按钮配合使用。但我希望列表在单击时重定向到另一个页面,但仍然在主控制器中保存此值。
Here is the Codepen attempt.
这是Codepen的尝试。
Thank you.
1 个解决方案
#1
0
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
.
好吧,首先ng-click =“do”绝对不会做任何事情。它应该是ng-click =“do()”,当然,你必须在你的控制器中有一个名为do的函数来执行一个动作。
The 2nd. problem is: you're inside ngRepeat
, it creates a child $scope
, so you have to use the Dot Rule
:
第二个。问题是:你在ngRepeat里面,它会创建一个子$ scope,所以你必须使用Dot规则:
$scope.model = {};
Then, you can do it:
然后,你可以这样做:
ng-click="model.itemValue = item"
Check the forked DEMO
检查分叉的DEMO
#1
0
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
.
好吧,首先ng-click =“do”绝对不会做任何事情。它应该是ng-click =“do()”,当然,你必须在你的控制器中有一个名为do的函数来执行一个动作。
The 2nd. problem is: you're inside ngRepeat
, it creates a child $scope
, so you have to use the Dot Rule
:
第二个。问题是:你在ngRepeat里面,它会创建一个子$ scope,所以你必须使用Dot规则:
$scope.model = {};
Then, you can do it:
然后,你可以这样做:
ng-click="model.itemValue = item"
Check the forked DEMO
检查分叉的DEMO