Angular 中的范围继承 $broadcast
Scope Inheritance $broadcast in Angular
我正在尝试在 Angular 中设置范围广播。 Datetimepicker 应该在 parent 网格中定义,children 应该继承它。我这样试过:
$scope.dtBODStopValue = new Date()
$scope.dtBODStartValue = new Date(new Date(new Date().getTime() - 7 * MS_PER_DAY));
改变Date/Time并广播到其他网格
$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"/>
根据文档 $broadcast 是范围方法
$scope.$broadcast(name, args);
所以你的情况应该是
$scope.$broadcast('datepickerUpdate', dtBODStartValue, dtBODStopValue);
然后是 child
范围内的听众
$scope.$on('datapickerUpdate', function (event, dtBODStartValue, dtBODStopValue) {
//do stuff on change
})
我正在尝试在 Angular 中设置范围广播。 Datetimepicker 应该在 parent 网格中定义,children 应该继承它。我这样试过:
$scope.dtBODStopValue = new Date()
$scope.dtBODStartValue = new Date(new Date(new Date().getTime() - 7 * MS_PER_DAY));
改变Date/Time并广播到其他网格
$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"/>
根据文档 $broadcast 是范围方法
$scope.$broadcast(name, args);
所以你的情况应该是
$scope.$broadcast('datepickerUpdate', dtBODStartValue, dtBODStopValue);
然后是 child
范围内的听众
$scope.$on('datapickerUpdate', function (event, dtBODStartValue, dtBODStopValue) {
//do stuff on change
})