【问题标题】:How to return only one directive between two almost identical ones in AngularJS?如何在AngularJS中两个几乎相同的指令之间只返回一个指令?
【发布时间】:2020-10-02 07:43:06
【问题描述】:

我如何在两个相同的指令中只包含一个指令,其中一个具有已弃用的功能,而另一个未弃用?

  1. 无法删除已弃用的文件(文件已删除)。
  2. 我记得有一种方法可以获取所有同名指令并返回它们的数组,让我选择应该返回哪些指令,但我再也找不到了。
var app = angular.module('myModule');

app.directive('myDirective1',
// returns all the needed things;
);

app.directive('myDirective1',
// returns all the needed things, plus some additional stuff;
);

如何只返回/注册第一个 myDirective1 而没有第二个?

【问题讨论】:

    标签: angularjs angularjs-directive angularjs-decorator


    【解决方案1】:

    找到方法

    .config(['$provide', function ($provide) {
        // Returns the second registered uiGridOdataDirective from module,
        // so we dont call the same functionality twice.
        $provide.decorator('uiGridOdataDirective', ['$delegate', function ($delegate) {
            return [ $delegate[1] ];
        }]);
    }]);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-03
      • 2023-03-29
      相关资源
      最近更新 更多