简体   繁体   English

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

[英]Pass function from angular1 to downgraded angular2 component

Problem: 问题:

I am unable to get a function to pass successfully to a downgraded Angular 2 component. 我无法获得成功传递给降级的Angular 2组件的功能。 I've tried just about every way I can think to pass things in but I am only able to get strings passed in via string interpolation -> some-attribute={{controller.property}}. 我已经尝试了几乎所有我认为可以传递的方法,但我只能通过字符串插值传递字符串 - > some-attribute = {{controller.property}}。 Here are some of the things I've tried (yes, I know some of them don't make sense...) 以下是我尝试过的一些事情(是的,我知道其中一些没有意义......)

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

Setup: 建立:

Here is my existing setup which is working for data but not for functions: 这是我现有的设置,它适用于数据,但不适用于功能:

Angular 1 usage Angular 1用法

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

Upgrade/Downgrade adapter 升级/降级适配器

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

Angular 2 definition Angular 2定义

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

  @Input() inputName: any;

  constructor() {}
}

The Angular docs even show how to set it up but they don't give any examples of actual usage. Angular文档甚至展示了如何设置它,但它们没有提供实际使用的任何示例。 Am I missing something or can this just not be done? 我错过了一些东西还是可以做到这一点?

Use AngularJS kebab case like this, seems to work for me: 像这样使用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