Skip to content
This repository was archived by the owner on Oct 7, 2021. It is now read-only.
This repository was archived by the owner on Oct 7, 2021. It is now read-only.

Fetching from a link isn't working (in Angular?) #22

@Smolli

Description

@Smolli

There is this setup:

export class CustomerResource extends HalResource {
    @HalProperty()
    id: number
    @HalProperty()
    name: string
    // @HalProperty(StoreResource)
    // stores: Array<Store>
}

@Injectable()
export class CustomerService {

    getCustomers(): Promise<CustomerResource[]> {
        const uri = this.createUrl('customer')
        return this.client.fetchArray(uri, CustomerResource)
    }

    getStores(customer: CustomerResource): Promise<StoreResource[]> {
        const resource = customer.link('stores')
        const link = resource.fetch()
        return (<Promise<any>>link)
    }    
}

When I call customerService.getStores(customer) I get the error Error: object is not hal resource [<array of stores>]. It doesn't change a thing if I comment out the stores field in the CustomerResource type or not. However, fetching the customer in the first place works fine. And I don't see any difference to your example code (besides the await statements) in the wiki.

There is a alternate approach that actually works, but I guess it wasn't meant to be (looks a bit ugly to me ;)

const link = customer.link('stores').uri.uri
return this.client.fetchArray(link, StoreResource)

As you may already have guessed by the @Injectable() decorator, I'm using Angular 5 and calling resource.fetch() returns a ZoneAwarePromise. Maybe that's a clue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions