AngularJS 广播

AngularJS broadcasting

我有一个刷新函数需要广播给子控制器。我在父控制器中做了这样的事情:

      // Refresh/Cancel
  $scope.OnGridBODRefresh() = {
        function () {
         $scope.$broadcast('refresh',$scope.dtBODStartValue,$scope.dtBODStopValue);                                  
        }          
        } 

在子控制器中:

      // Refresh/Cancel
  $scope.OnGridBODRefresh = function () {        
    // Filter setzen
    kendoHelper.SetDataSourceFilters($scope.gridBODProductionRequests.dataSource, "BODTime", "gte", $scope.dtBODStartValue);    // gte Kendo Operator
    kendoHelper.SetDataSourceFilters($scope.gridBODProductionRequests.dataSource, "BODTime", "lte", $scope.dtBODStopValue);       // lte Kendo Operator
  }
   
  $scope.dtChildStopValue = new Date();
  $scope.dtChildStartValue = new Date($scope.dtChildStopValue - 7 * TIMEINTERVAL_PER_DAY_MS);
     
      $scope.$on('refresh', function (event, dtBODStartValue, dtBODStopValue) {
           $scope.dtChildStartValue = dtBODStartValue;
           $scope.dtChildStopValue = dtBODStopValue;
         }
         )         

它应该在“取消”按钮上激活。我有一个错误:

"$scope.OnGridBODRefresh is not a function"

在控制台中。有人知道吗?

这是我的控制器和视图之间的 link:

<table border="0" class="navigationBar">
    <tr>
        <td class="navigationBar-left">
            ({{refreshcount}})
            <kendo-button class="k-primary button button-save" ng-click="OnGridBODSave()">Save</kendo-button>
            <kendo-button class="k-primary button button-cancel" ng-click="OnGridBODRefresh()">Cancel</kendo-button>
        </td>
        <td class="navigationBar-right">
            @PLanguageTexts.TXT_AUTO_REFRESH:  <input type="checkbox" name="checkBoxAutomaticRefresh" ng-model="checkBoxAutomaticRefreshValue" ng-true-value="1" ng-false-value="0" ng-change="OnCheckBoxAutomaticRefreshChange(e)">
            | 
            @PLanguageTexts.TXT_BOD_TIME
          <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"/>
        </td>
    </tr>
</table> 


 <div ng-controller="BODProductionRequestsCtrl">  
           <div kendo-grid="gridBODProductionRequests" k-options="gridBODProductionRequests(dataItem)">
              <div k-detail-template>
                <kendo-tabstrip>
                  <ul>
                      <li class="k-state-active">@PLanguageTexts.TXT_COMMENT</li>
                  </ul>
                  <div>
                    <textarea id="BODProductionRequestsComment" class="textarea-gridComment" ng-model="dataItem.Comment" ng-change="OnCommentChange(dataItem, gridBODProductionRequests)"></textarea>
                  </div>
                </kendo-tabstrip>
              </div>
        </div>
        {{dtChildStartValue}}
  </div>  
  // Refresh/Cancel
$scope.OnGridBODRefresh = function () {
        $scope.$broadcast('refresh',$scope.dtBODStartValue,$scope.dtBODStopValue);                                  
    }  

我不明白为什么要将函数包装到对象中。如果您删除函数周围的括号,它会像魅力一样工作。

另一个问题是您的 ng-click 不在链接到控制器的 div 内。尝试这样做。如果它不起作用,kendo 也可能存在问题,我无法提供帮助。

 <div ng-controller="BODProductionRequestsCtrl">  
    <table border="0" class="navigationBar">
            <tr>
                <td class="navigationBar-left">
                    ({{refreshcount}})
                    <kendo-button class="k-primary button button-save" ng-click="OnGridBODSave()">Save</kendo-button>
                    <kendo-button class="k-primary button button-cancel" ng-click="OnGridBODRefresh()">Cancel</kendo-button>
                </td>
                <td class="navigationBar-right">
                    @PLanguageTexts.TXT_AUTO_REFRESH:  <input type="checkbox" name="checkBoxAutomaticRefresh" ng-model="checkBoxAutomaticRefreshValue" ng-true-value="1" ng-false-value="0" ng-change="OnCheckBoxAutomaticRefreshChange(e)">
                    | 
                    @PLanguageTexts.TXT_BOD_TIME
                  <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"/>
                </td>
            </tr>
        </table> 



                               <div kendo-grid="gridBODProductionRequests" k-options="gridBODProductionRequests(dataItem)">
                                      <div k-detail-template>
                                        <kendo-tabstrip>
                                          <ul>
                                              <li class="k-state-active">@PLanguageTexts.TXT_COMMENT</li>
                                          </ul>
                                          <div>
                                            <textarea id="BODProductionRequestsComment" class="textarea-gridComment" ng-model="dataItem.Comment" ng-change="OnCommentChange(dataItem, gridBODProductionRequests)"></textarea>
                                          </div>
                                        </kendo-tabstrip>
                                      </div>
                                </div>
                                {{dtChildStartValue}}
                          </div>