1

所以我对组件、绑定和 Angular 2 范式还比较陌生。我想让我的 Angular 1.3 应用程序准备好传输,所以我一直在尝试采用新的组件指令。

不过,我无法克服不可分配的绑定错误!

这是我包含组件的地方:

<schedule currentSchedule="[]" class="panel"></schedule>

以及组件本身:

app.component('schedule', {
bindings: {
    currentSchedule: "="
},
controllerAs: 'SchedCtrl',
controller: function(Schedules) 
{

    var scope = this

    Schedules.refresh()
    .then(function(result) {
        scope.currentSchedule = result
    })
},
templateUrl: "templates/schedule.html"
})

和组件模板:

<div ng-repeat="apt in SchedCtrl.currentSchedule | orderBy: 'App_DtTm'">
    {{apt.name}}
</div>

我觉得我在这里遗漏了一些非常明显的东西。任何帮助将不胜感激。

4

1 回答 1

0

该错误意味着您正在尝试[]通过双向绑定为表达式分配值。

https://docs.angularjs.org/error/ $compile/nonassign

如果您确实需要双向绑定,请使用父范围的属性。

<schedule currentSchedule="parentCtrl.currentSchedule" class="panel"></schedule>

如果您不需要双向绑定,请使用<代替=并将初始计划和当前计划分开。

app.component('schedule', {
  bindings: {
    initialSchedule: "<"
  },
  controllerAs: 'SchedCtrl',
  controller: function(Schedules) 
  {

    var scope = this
    scope.currentSchedule = scope.initialSchedule

    Schedules.refresh()
      .then(function(result) {
        scope.currentSchedule = result
    })
  },
  templateUrl: "templates/schedule.html"
})
于 2016-02-18T03:08:20.813 回答