【问题标题】:How to get around Error: $compile:nonassign Non-Assignable Expression in angular 1.5 component如何解决错误:$compile:nonassign Non-Assignable Expression in angular 1.5 组件
【发布时间】:2016-05-30 01:03:46
【问题描述】:

所以我对组件、绑定和 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>

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

【问题讨论】:

    标签: angularjs angularjs-bindings angularjs-components


    【解决方案1】:

    该错误表示您正在尝试通过双向绑定为表达式[] 赋值。

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

    如果确实需要双向绑定,请使用父作用域的属性。

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

    如果您不需要双向绑定,请使用&lt; 而不是=,并将初始计划和当前计划分开。

    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"
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 2022-09-22
      • 2020-05-11
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 2018-01-09
      • 1970-01-01
      相关资源
      最近更新 更多