加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:08:55 所属栏目:安全 来源:网络整理
导读:问题: 我无法获得成功传递给降级的Angular 2组件的功能.我已经尝试了几乎所有我认为可以传递的方法,但我只能通过字符串插值传递字符串 – 一些属性= {{controller.property}}.以下是我尝试过的一些事情(是的,我知道其中一些没有意义……) some-function="co
问题:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读