angularjs - 从 Angular 1 传递函数以降级 Angular 2 组件

标签 angularjs angular ng-upgrade angular2-upgrade

问题:

我无法获得成功传递给降级的 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 docs甚至展示了如何设置它,但他们没有给出任何实际使用示例。 我是否遗漏了什么,或者这不能完成吗?

最佳答案

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

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

关于angularjs - 从 Angular 1 传递函数以降级 Angular 2 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41557450/

相关文章:

angular - 如何在@angular/google-maps 模块中用自定义图标替换谷歌地图标记图标

javascript - 递归迭代嵌套对象以更改所有出现的键值

angularjs - 吴升级 : Unable to use templateUrl when upgrading Angular1 components

javascript - 延迟加载js/优化加载时间

javascript - AngularJS 指令 : Reference local variables from external HTML file used in template

angularjs - 更改 $includeContentRequested 上的源网址

javascript - Protractor 如何点击空白处

javascript - Angular 4 : How to watch an object for changes?

angular - 使用 ngUpgrade 测试 Angular 应用程序失败,返回 "Unknown provider: ng2.InjectorProvider <- ng2.Injector"

javascript - 将 AngularJS 迁移到 Angular 4,5(带 DEMO)