Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 更改检测无法正常工作_Angular_Ngrx - Fatal编程技术网

Angular 更改检测无法正常工作

Angular 更改检测无法正常工作,angular,ngrx,Angular,Ngrx,我用的是angular4,这是我的模板 <span>My ID:{{ peerId$ | async }}</span> <span>My ID:{{ peerId }}</span> myid:{{peerId$| async} 我的ID:{{peerId} 这是组件代码 export class AppComponent implements OnInit { peerId: string = 'Guy'; peerId

我用的是angular4,这是我的模板

<span>My ID:{{ peerId$ | async }}</span>
<span>My ID:{{ peerId }}</span>
myid:{{peerId$| async}
我的ID:{{peerId}
这是组件代码

export class AppComponent implements  OnInit {

    peerId: string = 'Guy';
    peerId$: Observable<string>;


    constructor(private store:Store<AppState>) {

    }

    ngOnInit() {

        this.peerId$ = this.store.select("peerId") as Observable<string> ;
        this.peerId$.subscribe((peerId:string)=>{
            this.peerId = peerId; // changed from 'guy' to 'blabla' in debug 
            // in template nothing changes 
        });   
导出类AppComponent实现OnInit{
peerId:string='Guy';
peerId$:可观察;
构造函数(私有存储:存储){
}
恩戈尼尼特(){
this.peerId$=this.store.select(“peerId”)作为可观察对象;
this.peerId$.subscribe((peerId:string)=>{
this.peerId=peerId;//在调试中从'guy'更改为'blabla'
//在模板中没有任何更改
});   
Dom元素中的更改不会被触发,除非我关注页面中的某种输入,然后更改才会发生


我已经从angular2升级到4,但仍然存在相同的问题,如果我编写一个简单的setTimeout或Observable,我可以立即看到更改,因此我认为问题在于使用ngrx/store进行更改检测。

在模块importStoreModule.provideStore({peerId:peerReducer},{peerId:'Searching…')中初始化存储的位置和方式在
@NgModule({imports:[…])
中,我假设。那应该没问题。我会补充说,如果存储缩减器是数组类型,则会发生更改,但如果它是字符串,则不会。在哪里以及如何初始化存储?在模块importStoreModule.provideStore({peerId:peerReducer},{peerId:'search…')中的
@NgModule中({imports:[…]})
我假设。那应该没问题。我要补充的是,如果存储缩减器是数组类型,则会发生更改,但如果是字符串则不会。