2017-01-09 74 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