2017-01-09 73 views
3

问题:通功能

我无法得到一个功能成功地传递到降级角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"; 

设置:

这里是我现有的设置这是工作用于数据而不是功能:

角1使用

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

升级/降级适配器

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

角2定义

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

    @Input() inputName: any; 

    constructor() {} 
} 

Angular docs甚至展示了如何设置它,但他们不给实际使用的任何例子。 我错过了一些东西吗?

回答

1

使用AngularJS烤肉情况就是这样,似乎为我工作:

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

这奏效了我。 – Haymaker87