AngularJS广播

时间:2015-04-21 13:54:04

标签: javascript angularjs javascript-events angular-broadcast

具有需要向儿童控制器广播的刷新功能。我在父控制器中做了类似的事情:

      // 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在控制台中不是一个函数”。有谁知道这个?感谢

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

<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>  

1 个答案:

答案 0 :(得分:1)

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

我不明白为什么要将你的功能包装到一个物体中。如果你移除功能周围的括号,它就像魅力一样。

另一个问题是您的ng-click不在链接到控制器的div内。试着这样做。如果它不起作用,可能还会出现剑道问题,我无法提供帮助。

 <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>