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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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 Nativescript RadListView未更新_Angular_Typescript_Nativescript - Fatal编程技术网

从另一页推送时,Angular Nativescript RadListView未更新

从另一页推送时,Angular Nativescript RadListView未更新,angular,typescript,nativescript,Angular,Typescript,Nativescript,我有RadListView,它从http请求获取数据: <RadListView #listView separatorColor="transparent" pullToRefresh="true" (pullToRefreshInitiated)="refreshFavorites($event);" *ngIf="filteredItems && filteredItems.length; else noItems" row="2"

我有
RadListView
,它从
http
请求获取数据:

<RadListView #listView  separatorColor="transparent"
        pullToRefresh="true" (pullToRefreshInitiated)="refreshFavorites($event);" *ngIf="filteredItems && filteredItems.length; else noItems" row="2"
            [items]="filteredItems" marginTop="-100" (touch)="dismissKeyboard($event)">
    <ng-template let-item="item" let-i="index">
        <GridLayout columns="10,*,10">
            <GridLayout *ngIf="item" (tap)="goToInner(item)" [nsRouterLink]="['../favorite', item.ean]" pageTransition="slide"  shadow='6' cornerRadius='5' col="1" columns="*,auto" class="p-8 m-b-8 m-x-8" borderRadius="8"
            backgroundColor="white">
                <GridLayout class="favorite-card" col="0" columns="150,*,auto" rows="auto,auto,auto">
                    <Image col="0" rowSpan="3" class="thumbnail m-r-12" stretch="aspectFit" *ngIf="item.images"
                        [src]="item.images.large.url"></Image>
                        <StackLayout col="1" row="1" verticalAlingment="center">
                                <Label  class="h3 title m-t-4" marginBottom="0" textWrap="true" maxLines="2" [text]="item.productTitle"></Label>
                                <Label class="h5 caption" [text]="item.manufacturer"></Label>
                        </StackLayout>
                </GridLayout>
                <StackLayout col="1" verticalAlignment="top" (tap)="removeFromFavorites(item, i)">
                        <Image horizontalAlignment="right" src="~/images/favorite-active.png" width="20" height="20"></Image>
                </StackLayout>
            </GridLayout>
        </GridLayout>
    </ng-template>
</RadListView>

我做错了什么,为什么不更新?为什么我的RadListView在从另一个组件调用函数后没有更新,而是从它自己的组件更新?这两个组件中的项目都相同。

您需要一个创建服务并使用行为主题,如图所示。使用注入组件不是常见的做法。 为您效劳

filteredItems;



public filteredItemsSubsSource = new BehaviorSubject(new ObservableArray<item>());
public filteredItemsSubs = this.filteredItemsSubsSource.asObservable();

addItem(item){
    this.filteredItems.push(item);
    this.filteredItemsSubsSource.next(filteredItems);
}


你可以创建一个游乐场吗?
providers: [InnerComponent],    
constructor(private inner: InnerComponent){}
addItem(item){
    this.inner.update(item)
}
filteredItems;



public filteredItemsSubsSource = new BehaviorSubject(new ObservableArray<item>());
public filteredItemsSubs = this.filteredItemsSubsSource.asObservable();

addItem(item){
    this.filteredItems.push(item);
    this.filteredItemsSubsSource.next(filteredItems);
}
providers: [Service],    
constructor(private _service: Service){}

addItem(item){
    this._service.addItem(item);
}
this._service.filteredItemsSubs.subscribe(
            (filteredItems) => {
                this.filteredItems= filteredItems;

            }
        );