2016-09-15 50 views
1

我有组分:角2主机异步结合

@Component({ 
    selector: 'my-selector', 
    template: `<div>html code goes here</div> 
    `, 
    host: { 
     '[style.background]': "'url(' + (myobj | async).background + ') 50% no-repeat'" 
    }, 
    styleUrls: ['myComponent.scss'], 
    changeDetection: ChangeDetectionStrategy.OnPush 
}) 
export class MyComponent { 
    @select(getMyobj) 
    myobj: Myobj; 
} 

我需要绑定到我的主机元件background.I'm得到背景在rxjs对象(观察不到),所以我说“异步”,但我m得到错误消息:“模板解析错误:无法找到管'异步'”。

我该如何让它工作?

回答

1

确保将CommonModule导入模块声明中。 CommonModule包含异步管道。

我已经复制到我自己的模块中,我遇到了完全相同的问题,并忽略了CommonModule。

import { NgModule } from '@angular/core'; 
import { CommonModule } from '@angular/common'; 

@NgModule({ 
    declarations: [MyComponent], 
    providers: [], 
    imports: [CommonModule] 
}) 
export class MyModule { 
}