【问题标题】:Can't read $scope in Ionic 1 / angular无法在 Ionic 1 / angular 中读取 $scope
【发布时间】:2017-09-19 07:05:08
【问题描述】:

我有这段 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 做一些事情。

【问题讨论】:

  • 在控制器 $scope.dateTime = { timeValue : new Date() } 和模型中使用 ng-model="dateTime.timeValue"
  • 我已经发布了angular的答案和文档链接,请查看

标签: angularjs ionic-framework


【解决方案1】:

您需要使用“点符号”。因为继承,简单的值不会做双向绑定。

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

在控制器中使用

$scope.dateTime = { timeValue : '' } 

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

herehere 了解更多详情。

希望这对您有所帮助!

【讨论】:

  • 其实我还是需要你的帮助。做console.log($scope.dateTime.timeValue);不会显示我选择的时间,它只会显示为空。
  • 有没有加ng-model dateTime.timeValue
  • 对,别理我,早上太早了。我已将 $scope.dateTime = { timeValue : '' } 放在函数中,当然它会将日期设置为空。我把它们从里面移了出来,它就完成了。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-04
  • 2020-09-26
  • 1970-01-01
  • 1970-01-01
  • 2020-08-10
  • 2015-05-21
  • 1970-01-01
相关资源
最近更新 更多