Angular 使用';将空属性指定给角度中的对象时,视图不更新;rxjs/observable/zip';

Angular 使用';将空属性指定给角度中的对象时,视图不更新;rxjs/observable/zip';,angular,rxjs,ngrx,angular-ng-if,Angular,Rxjs,Ngrx,Angular Ng If,组件更新本地属性/变量后,视图无法更新,这是我遇到的问题 在我的组件代码中,我创建了一个“newAlbum”属性,并最初将其分配给null。稍后在我的组件中调用名为openCreateForm的方法时,我希望为我的“newAlbum”属性赋值,然后希望使用简单的*ngIf 这是我的组件中的typescript代码 newAlbum: { title: string, editableImageList: EditableImage[], description: string, fromDate

组件更新本地属性/变量后,视图无法更新,这是我遇到的问题

在我的组件代码中,我创建了一个“
newAlbum
”属性,并最初将其分配给null。稍后在我的组件中调用名为
openCreateForm
的方法时,我希望为我的“newAlbum”属性赋值,然后希望使用简单的
*ngIf

这是我的组件中的typescript代码

newAlbum: { title: string, editableImageList: EditableImage[], description: string, fromDate: string} = null;

constructor(private store: Store<any>,
                private fileService: FileService) {
    // more stuff here that isn't important
    }


openCreateForm(fileList: File[]) {
    const editableImageObservableList = _.map(fileList, (file) => {
        return this.fileService.imageFileToDataUrl(file)
            .map((dataUrl) => {
                return new EditableImage(null, dataUrl);
            });
    });
    zip(...editableImageObservableList).subscribe((editableImageList: EditableImage[]) => {
        this.newAlbum = {
            title: 'My new album',
            editableImageList,
            description: null,
            fromDate: String(moment().year())
        };
    });
}
newAlbum:{title:string,editableImageList:EditableImage[],description:string,fromDate:string}=null;
构造函数(私有存储:存储,
专用文件服务:文件服务){
//这里有更多不重要的东西
}
openCreateForm(文件列表:文件[]){
const-editableImageObservableList=uz.map(文件列表,(文件)=>{
返回此.fileService.imageFileToDataUrl(文件)
.map((数据URL)=>{
返回新的EditableImage(null,dataUrl);
});
});
zip(…EditableMageObservableList).subscribe((EditableMageList:EditableMimage[])=>{
this.newAlbum={
标题:“我的新专辑”,
可编辑图像列表,
description:null,
fromDate:String(矩().year())
};
});
}
这是我的组件模板中的HTML(在外部文件中)


此内容应显示在。。。
在Chrome Dev Tools中调试并使用正确的参数启动
openCreateForm
方法时,
this.newAlbum
被正确地分配了正确的属性,并且不再为null。。。但是,我的视图没有得到更新。如果我在界面上的某些div之间切换,则在返回或切换视图中的选项卡时,
*ngIf=“newAlbum”
会正常工作。你能告诉我为什么更新没有被触发,或者我能做些什么来强制更新吗?非常感谢


如果以上任何一项都没有意义,请说明,我将改写这个问题。。。再次感谢。

newAlbum
属于
Any
类型,因为它是一个对象文本。与其依赖duck类型来确保对象的新版本被更改检测到,不如为它创建一个接口

interface Album{
     title: string; 
     editableImageList: EditableImage[]; 
     description: string; 
     fromDate: string
}
然后

在您的订阅中:

this.newAlbum = <Album>{
   title: 'My new album',
   editableImageList,
   description: null,
   fromDate: String(moment().year())
};
this.newAlbum={
标题:“我的新专辑”,
可编辑图像列表,
description:null,
fromDate:String(矩().year())
};

这可能有助于更改检测跟踪属性,因为在添加此属性时,它是一种众所周知的类型。

。changeDetectorRef.detectChanges();在新的
任务完成后,这张专辑可以运行,但感觉像是黑客!这种变化似乎发生在外部。
imageFileToDataUrl
EditableImage
做什么?另外,如何调用
openCreateForm
openCreateForm
是在处理从
input type=file
中选择的文件时调用的
imageFileToDataUrl
将所选文件转换为数据URL的观察表。EditableImage是一个提供getter和setter的类/类型。我试过了,但似乎没有任何区别。。。这就好像
zip(…EditableMageObservableList).subscribe
不会触发Angular中的更改检测?尝试在中重现问题,但一切正常
newAlbum: Album;
this.newAlbum = <Album>{
   title: 'My new album',
   editableImageList,
   description: null,
   fromDate: String(moment().year())
};