无法读取Ionic 1 / angular中的$ scope(Can't read $scope in Ionic 1 / angular)

编程入门 行业动态 更新时间:2024-10-24 10:17:32
无法读取Ionic 1 / angular中的$ scope(Can't read $scope in Ionic 1 / angular)

我有这个HTML:

<div class="item item-icon-left" ion-datetime-picker="" time="" ng-model="timeValue"> <i class="icon ion-ios-clock positive"></i> <p><strong">{{timeValue | date:'HH:mm'}}</strong></p> </div>

在我的控制器中,我有这个功能,当激活切换时将触发:

$scope.funCheck = function(check) { console.log($scope.timeValue); };

我使用这个: https : //github.com/katemihalikova/ion-datetime-picker来选择时间并设置它。

它可以很好地选择时间,但是,我正在设定未定义的功能,我不知道为什么。 我希望得到我选择的时间,并使用$ Scope在我的控制器中做一些事情。

I have this piece of HTML:

<div class="item item-icon-left" ion-datetime-picker="" time="" ng-model="timeValue"> <i class="icon ion-ios-clock positive"></i> <p><strong">{{timeValue | date:'HH:mm'}}</strong></p> </div>

And in my controller I have this function that will fire when a toggle is activated:

$scope.funCheck = function(check) { console.log($scope.timeValue); };

And I use this: https://github.com/katemihalikova/ion-datetime-picker to pick a time and set it.

It works fine to pick the time, however, in the function I'm geting undefined and I dont know why. I want to get the time I picked and do some stuff in my controller with the $Scope.

最满意答案

你需要使用“点符号”。 由于继承,简单值不会进行双向绑定。

请使用以下代码进行与离子的双向数据绑定

在控制器中使用

$scope.dateTime = { timeValue : '' }

在模型ng-model="dateTime.timeValue"

从这里和这里了解更多详情。

希望这很有帮助!

You need to be using "dot notation". Because of inheritance, simple values will not do two way binding.

Please use the following code for two way data binding with ionic

use in controller

$scope.dateTime = { timeValue : '' }

and in model ng-model="dateTime.timeValue"

Read more details from here and here.

Hope this well help!

更多推荐

本文发布于:2023-07-31 19:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347236.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:angular   Ionic   read   scope

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!