小编Mar*_*hop的帖子

将函数从 Angular1 传递到降级的 Angular2 组件

问题:

我无法将函数成功传递给降级的 Angular 2 组件。我已经尝试了几乎所有我能想到的传递内容的方法,但我只能通过字符串插值 -> some-attribute={{controller.property}} 传递字符串。以下是我尝试过的一些方法(是的,我知道其中一些没有意义......)

some-function="controller.function";
some-function="{{controller.function}}";  //<-- works for data, not functions
[some-function]="{{controller.function}}";
[someFunction]="controller.function";
[(someFunction)]="controller.function";
Run Code Online (Sandbox Code Playgroud)

设置:

这是我现有的设置,适用于数据但不适用于函数:

角度 1 用法

<my-component data-input-name="{{controller.name}}"></my-component>
Run Code Online (Sandbox Code Playgroud)

升级/降级适配器

angular.module('myModule').directive('myComponent',
    downgradeComponent({
      component: MyComponent, 
      inputs: ['inputName']
    }) as angular.IDirectiveFactory);
Run Code Online (Sandbox Code Playgroud)

Angular 2 定义

@Component({
  selector: 'my-component',
  templateUrl: './my.component.html',
  styleUrls: ['./my.component.css']
})
export class MyComponent implements OnInit {

  @Input() inputName: any;

  constructor() {}
}
Run Code Online (Sandbox Code Playgroud)

Angular 文档甚至展示了如何设置它,但没有给出任何实际使用的示例。我错过了什么或者这不能完成吗?

angularjs angular2-upgrade ng-upgrade angular

5
推荐指数
1
解决办法
1155
查看次数

标签 统计

angular ×1

angular2-upgrade ×1

angularjs ×1

ng-upgrade ×1