仅在使用* ngIf指令时显示属性

时间:2019-03-20 09:53:51

标签: angular

问题:仅使用 * ngIf 指令显示属性。

list-folder.component.ts 文件中,我们检索以下文件夹:

ngOnInit(): void {
  this.service.getFolders().subscribe((res: Folder[]) => {
    this.listfolders = res;
  });
}

list-folder.component.html 文件中:

<div *ngFor="let folder of listfolders">
  <info-folder [folder]="folder"></info-folder>
</div>

info-folder.component.ts 文件中:

@Input()
public folder : Folder;

ngOnInit(): void {
  this.women = this.folder.person.filter(
    person => person.type === 'woman'
  );
  this.men = this.folder.person.filter(
    person => person.type === 'man'
  );
}

info-folder.component.html 文件中:

<person-detail [person]="women[0]"></person-detail>
<person-detail [person]="men[0]"></person-detail>

person-detail.component.ts 文件中,我检索到一个Person对象:

@Input()
public person: Person;

我在 ngOnInit 中放置了一个 console.log ,我可以看到带有填充名称的人员对象:

{ personId: 2, type: man, name: Fox }

person-detail.component.html 中,如果我使用 * ngIf 指令,则会很好地显示该名称:

<ng-container *ngIf="person.name">
  {{ person.name}}
</ng-container>

但没有 * ngIf

{{ person.name}}

不显示名称。我不明白为什么。

1 个答案:

答案 0 :(得分:0)

这是一个错字:

[SPTRequest playlistsForUserInSession:session callback:^(NSError *error, SPTListPage *object) {
        playListCount = [object.items count] - 1;
        if (object.items) {
            [object.items enumerateObjectsUsingBlock:^(SPTPartialPlaylist *obj, NSUInteger idx, BOOL *stop) {
                [playlistURI addObject:obj.uri];
                if (idx == object.items.count - 1) {
                    [weakSelf requestsTracks:playlistURI withSession:session];
                }
                spotifySynching = NO;
            }];
        }else{
            spotifySynching = NO;
            [self stopAnimatingTotalSpinner];
            [self updateProgressDisplays];
        }
    }];

(SPTListPage *)object;
[object requestNextPageWithSession:session callback:^(NSError *error, SPTListPage *object) {
        [tracksURI addObjectsFromArray:object.items];
        if ([object hasNextPage]) {
            [self hasNextTrack:object withSession:session withNewObject:newObject];
        }else{
            [self requestsTracks:newObject withSession:session];
        }
    }];


   [SPTRequest requestItemAtURI:obj withSession:session callback:^(NSError *error, SPTPlaylistSnapshot *object) {
        if (error != nil) {
            NSLog(@"*** Auth error: %@", error);
            return;
        }

        [tracksURI addObjectsFromArray:object.firstTrackPage.items];

        if ([object.firstTrackPage hasNextPage]) {
            [self hasNextTrack:object.firstTrackPage withSession:session withNewObject:newObject];
        }else{
            [self requestsTracks:newObject withSession:session];
        }
    }];

另外console.log并没有显示正确的人,因为它没有显示任何类型的人,即男人或女人:

this.men = this.folder.person.filter(
  partie => person.type === 'man' // should be person => person.type === 'man'
);