Angular不会使用bindToController绑定来自控制器的数据

时间:2015-03-16 18:11:01

标签: angularjs

我一直在努力解决这个问题。如果我只是将它绑定到控制器上下文,AngularJS就不会绑定数据。 如果我尝试通过$ scope将其更改为简单绑定 - 一切正常。

诀窍在于分配函数loadComments的行 - 奇怪的是,如果我删除它,一切正常。

Angular的版本是1.4.0-beta.5

这是我的代码:

angular.module('my-app')
.directive 'myComments',
  ->
  directive = 
    restrict: 'E'
    scope: true
    controller: 'CommentsController'
    controllerAs: 'ctrl'
    bindToController: true
    templateUrl: 'comments.html'
    replace: true

.controller 'CommentsController', () ->
  this.name = 'Comments'

  this.loadComments = ->

// The template is here
section.comments
  header ng-bind='ctrl.name'

谢谢!

1 个答案:

答案 0 :(得分:0)

实际上找到了答案 - 你必须在控制器的末尾明确地返回它。没有找到详细信息,但看起来根据返回结果,框架决定是否将其添加到范围。

相关问题