【问题标题】:Directive To Directive communication and call to a passed functionDirective To 指令通信并调用传递的函数
【发布时间】:2023-03-11 11:10:01
【问题描述】:

我有两个指令和一个具有功能测试的控制器。我的日期指令有一个按钮,点击时调用过滤器指令中的一个函数,该函数需要调用输入传递的函数,我尝试做$scope.$apply($attrs.entering);,但我得到$apply already in progress

在 HTML 中我有:

<filter entering="ctrl.test()">
  <date></date>
</filter>

app.directive('filter', function() {
  return {
    restrict: 'E',
    controller: function($scope, $element, $attrs) {
      this.sayHello = function() {
        // call function here $scope.$apply($attrs.entering);
      }
    }
  }
}
app.firective('date', function() {
  return {
    require: '^filter',
    link: function(scope, element, attrs, filterCtrl) {
      scope.isClicked = function() {
        filterCtrl.say()
      }
    }
  }
}

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    您不能在角度控制器中使用 $scope.$apply,因为它们已经隐式地包含在 $scope.$apply 中。您可以根据场景使用 $scope.$watch 或 $broadcast/$emit/$on。

    补充资料:http://jimhoskins.com/2012/12/17/angularjs-and-apply.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-05
      • 1970-01-01
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-23
      相关资源
      最近更新 更多