无法绑定到没有指令 + angularjs 标识符的控制器

Cannot bind to controller without identifier for directive + angularjs

本文关键字:angularjs 标识符 控制器 指令 绑定      更新时间:2023-09-26

我有一个这样的状态路由器:

$stateProvider
  .state('home', {
    url: '/',
    templateUrl: 'spa/layouts/home.html',
    controller: 'HomeController',
    controllerAs: 'ctrl'
  });

在我的家中.html模板我有:

<div class="row main-body">
  <aside class="col-md-2 sidebarNav">
    <div>...</div>
  </aside>
  <section class="col-md-10 main-container">
    <div>..</div>
    <my-list list-items={{ ctrl.listItems }}></my-list>
  </section>
</div>

在指令我的列表中,我有以下内容:

var templateUrl = 'spa/components/classList/classList.html';
angular
  .module('directives')
  .directive('myList', component);
function component() {
  return {
    templateUrl: templateUrl,
    controller: classListDir,
    contollerAs: '$ctrl',
    scope: {
      listItems: '@'
    },
    bindToController: true,
  };
}
classListDir.$inject = ['$scope'];
function classListDir($scope) {
  var $ctrl = this;
  console.log($ctrl);
}

我已经阅读并重读了 https://docs.angularjs.org/error/$compile/noident?p0=myList。我认为我的案子涉及第二个

/

/OKAY,因为该指令使用 controllerAs 属性来 覆盖

控制器标识符。

我仍然不断收到错误消息。我不明白与标识符错误的绑定。有人可以解释一下吗?

发现问题:

主持人:"$ctrl"

拼写错误。