【问题标题】:Binding '&' method in a routed component在路由组件中绑定“&”方法
【发布时间】:2017-03-15 10:12:11
【问题描述】:

考虑一下这个简化的 Angular 1.5.x 组件(全部在 jsfiddle 中):

appModule.component('mainComponent', {
  controller: function() {
    var x = 0;
    this.broadcast = function() {
      this.onUpdate({
        count: x++
      });
    };
    this.broadcast();
  },
  bindings: {
    onUpdate: '&'
  },
  template: '<input type="button" ng-click="$ctrl.broadcast()" value="add"/>'
});

HTML(在正文中)

<main-component on-update="this.count = count"></main-component>
Value in parent: {{count}}

点击组件按钮时,count变量正在更新('&' onUpdate绑定好)。

现在我想要一个从 ui.router 到组件的路由:

$stateProvider.state({
    name: 'state1',
    component: 'mainComponent',
    url: "#"
  });

导航到状态,导致Cannot read property '2' of null,删除 onUpdate 成员修复错误但破坏绑定。

我做错了什么?使用ui.router路由到组件时如何绑定组件的回调方法。

jsfiddle

【问题讨论】:

    标签: javascript angularjs angular-ui-router angular-components


    【解决方案1】:

    目前不支持使用“resolve”绑定回调,请参见此处:https://github.com/angular-ui/ui-router/issues/2793

    【讨论】:

      猜你喜欢
      • 2016-07-25
      • 1970-01-01
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 2012-01-30
      • 1970-01-01
      • 2019-12-23
      • 2017-10-07
      相关资源
      最近更新 更多