【问题标题】:Angular2 ngIf self.context.$implicit.'function name' is not a functionAngular2 ngIf self.context.$implicit.'function name' 不是函数
【发布时间】:2017-04-07 04:17:28
【问题描述】:

我正在通过 angular2-google-maps 在谷歌地图上显示路径。 我的问题是当我尝试根据特定条件在折线点上添加标记时,通过我的方法“isDisplayable()”检查

<sebm-google-map [latitude]="lat" [longitude]="lng">
    <sebm-google-map-polyline *ngFor="let user of followedUsers" [strokeColor]="user.IsSelected ? '#0277BD' : 'grey'">
        <sebm-google-map-polyline-point *ngFor="let userDataEvent of user.UserData.EventsList" [latitude]="userDataEvent.Lat" [longitude]="userDataEvent.Long">
            <sebm-google-map-marker *ngIf="userDataEvent.isDisplayable()" [latitude]="userDataEvent.Lat" [longitude]="userDataEvent.Long" [iconUrl]="user.IsSelected ? 'http://maps.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png' : 'http://maps.google.com/mapfiles/marker_grey.png' ">
            </sebm-google-map-marker>
        </sebm-google-map-polyline-point>
    </sebm-google-map-polyline>
</sebm-google-map>

我遍历我的用户以显示每个用户路径,并遍历事件列表以获取我的行的每个点。

我的 UserDataEvent 类:

import { EventData } from './EventData';

export class UserDataEvent {
    ID: string;
    Lat: number;
    Long: number;
    Date: string;

    ListsEvent: EventData[];

    isDisplayable(): boolean {
        let result: boolean = false;

        for (var eventData of this.ListsEvent)
        {
            if (eventData.TypeEvent == 1 || eventData.TypeEvent == 2 || eventData.TypeEvent == 7 || eventData.TypeEvent == 8) {
                result = true;
            }
        }
        return result;
    }
} 

我遇到了异常:“self.context.$implicit.isDisplayable 不是函数”

我不明白为什么

【问题讨论】:

    标签: angular angular-ng-if


    【解决方案1】:

    聚会晚了一点,但它可能不起作用,因为您没有为 ListsEvent 分配值。因此,您的 this.ListsEvent 的循环 var eventdata 会破坏您的代码。你也可以扔掉,用 let 代替。

    【讨论】:

    • 我不再为该项目的公司工作,但我已经解决了这个问题。还是谢谢你:)
    • @jorghe94 那是 2 年前的事了,但据我所知,“userDataEvent.isDisplayable()”中的 userDataEvent 不是 UserDataEvent。这就是它找不到函数的原因
    猜你喜欢
    • 2016-12-13
    • 2017-09-16
    • 2017-03-07
    • 2023-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    相关资源
    最近更新 更多