看不出有$watch的新值吗?

时间:2023-01-07 20:41:37

Here is my Plunker : Demo .
here is my code:
Controller :

这是我的柱塞:Demo。这是我的代码:控制器:

$scope.myDate='13930101';
    $scope.showDate=function() {
      PersianDatePicker.Show('thisDate', $scope.myDate);

    };

  $scope.$watch( 'myDate',
            function(newValue, oldValue){
                console.log('myDate Changed');
                console.log(newValue);
                console.log(oldValue);
            }
    );

Html :

Html:

  <input type="text" id="thisDate" ui-mask="9999/99/99"
          ng-model="myDate"  />


    <input type="button" value="test" ng-click="showDate()">   

The problem is : i can't see the changes for this : $scope.myDate='13930101';

问题是:我看不出这里的变化:$scope.myDate='13930101';

Or

My codes are wrong!
Any idea ? Thanks ahead

我的密码是错误的!任何想法?谢谢提前

2 个解决方案

#1


1  

Hay the problem is that the watcher is only for the input field, if you type something directly in the input field, the watcher triggers. But if you choose a date from the picker. it doesnt trigger.

问题是,观察者只针对输入字段,如果你在输入字段中输入一些东西,那么观察者就会触发。但是,如果你选择了采摘者的日期。它不触发。

#2


1  

This lib contains no documentation. From inspecting the scripts I see there is no other API function than Show() and therefore no callback like onSelect() which lets you bind the chosen date to your scope variable.

这个lib不包含文档。从检查脚本中,我看到没有其他API函数比Show(),因此没有类似onSelect()的回调,它允许您将所选择的日期绑定到范围变量。

I suggest to use another lib like this one which is already angularized.

我建议使用另一个像这样的lib,它已经是一个角化了。

#1


1  

Hay the problem is that the watcher is only for the input field, if you type something directly in the input field, the watcher triggers. But if you choose a date from the picker. it doesnt trigger.

问题是,观察者只针对输入字段,如果你在输入字段中输入一些东西,那么观察者就会触发。但是,如果你选择了采摘者的日期。它不触发。

#2


1  

This lib contains no documentation. From inspecting the scripts I see there is no other API function than Show() and therefore no callback like onSelect() which lets you bind the chosen date to your scope variable.

这个lib不包含文档。从检查脚本中,我看到没有其他API函数比Show(),因此没有类似onSelect()的回调,它允许您将所选择的日期绑定到范围变量。

I suggest to use another lib like this one which is already angularized.

我建议使用另一个像这样的lib,它已经是一个角化了。