作用域继承$角度广播

问题描述 投票:0回答:1

我正在尝试在Angular中设置范围广播。 Datetimepicker应该在父网格中定义,子级应该继承它。我尝试过这种方式:

      $scope.dtBODStopValue = new Date()
      $scope.dtBODStartValue = new Date(new Date(new Date().getTime() - 7 * MS_PER_DAY));

更改日期/时间并广播到其他网格

        $scope.dateTimePickerBODStart = {
        change: function () {
                $scope.$broadcast(dtBODStartValue,dtBODStopValue);
          $scope.OnGridRefresh();
        }
      };

$scope.dateTimePickerBODStop = {
        change: function () {
                $scope.$broadcast(dtBODStartValue,dtBODStopValue);
          $scope.OnGridRefresh();
        }
      };

HTML:

    <input kendo-date-time-picker="dateTimePickerBODStart" k-ng-model="dtBODStartValue" k-options="dateTimePickerBODStart"/>
    <input kendo-date-time-picker="dateTimePickerBODStop" k-ng-model="dtBODStopValue" k-options="dateTimePickerBODStop"/>    
javascript angularjs javascript-events angular-ui datetimepicker
1个回答
1
投票

根据文档$ broadcast是范围方法

$scope.$broadcast(name, args);

因此您的情况应该是

$scope.$broadcast('datepickerUpdate', dtBODStartValue, dtBODStopValue);

然后是child范围内的侦听器

$scope.$on('datapickerUpdate', function (event, dtBODStartValue, dtBODStopValue) {
  //do stuff on change
})
© www.soinside.com 2019 - 2024. All rights reserved.