Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了angularjs – 将函数从angular1传递到降级的angular2分量大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
问题:

我无法获得成功传递给降级的Angular 2组件的功能.我已经尝试了几乎所有我认为可以传递的方法,但我只能通过字符串插值传递字符串 – >一些属性= {{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 – 将函数从angular1传递到降级的angular2分量全部内容,希望文章能够帮你解决angularjs – 将函数从angular1传递到降级的angular2分量所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。