如何将依赖添加到 Angular 中模块的依赖列表?

How to add dependency to module's list of dependencies in Angular?

我正在尝试使用 angular-bootstrap-nav-tree 库,但我无法将 'angularBootstrapNavTree' 添加到我的模块的依赖项列表中。有错误 "Unknown provider: angularBootstrapNavTreeProvider <- angularBootstrapNavTree"

 angular.
  module('myApp').
  component('treeList', {
      template: ' <abn-tree tree-data="my_data"></abn-tree>',
      controller: function MyCtrl($http, $scope, dataContext, angularBootstrapNavTree) {              
          $scope.my_data = [{
              label: 'Languages',
              children: ['Jade','Less','Coffeescript'],
              classes: ["special", "red"]
          }]      
     });

您实际上必须将它添加到您的模块的依赖项列表,而不是控制器的依赖项。

angular.module('myApp',['angularBootstrapNavTree'])

你在你的语法中遗漏了一个 ; 和一个 },我修复了它:

angular.
  module('myApp').
  component('treeList', {
      template: '<abn-tree tree-data="my_data"></abn-tree>',
      controller: function MyCtrl($http, $scope, dataContext, angularBootstrapNavTree) {              
          $scope.my_data = [{
              label: 'Languages',
              children: ['Jade','Less','Coffeescript'],
              classes: ["special", "red"]
          }];      
      } 
   });

此外,您可能忘记将 angularBootstrapNavTree 添加到您的模块依赖项中:

angular.module('myApp', ['angularBootstrapNavTree']);