繁体   English   中英

将函数从angular1传递到降级的angular2分量

[英]Pass function from angular1 to downgraded angular2 component

问题:

我无法获得成功传递给降级的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";

建立:

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

Angular 1用法

<my-component data-input-name="{{controller.name}}"></my-component>

升级/降级适配器

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

Angular 2定义

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

  @Input() inputName: any;

  constructor() {}
}

Angular文档甚至展示了如何设置它,但它们没有提供实际使用的任何示例。 我错过了一些东西还是可以做到这一点?

像这样使用AngularJS kebab案例,似乎对我有用:

<my-component [data-input-name]="controller.name">
</my-component>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM