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不是一个函数"

在控制台中。有谁知道这一点?

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

<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 内。试着这样做。如果它不起作用,剑道也可能有问题,我将无法提供帮助。

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

相关内容

  • 没有找到相关文章

最新更新