Skip to content

Http Requests and Http Injectables #3086

Closed

Description

@tbragaf

Hi all !

I think httpInjectables are not working completely...


Problem 1

This is my Service:

@Component({
    viewInjector: [httpInjectables]
})
export class Service {
   constructor(http : Http) {
        ObservableWrapper.subscribe(http.get('http://api.github.com/users'), res => { 
            debugger
            this.people = res.json()
        });
   }
}

Which throws this:
image

This is my bootstrap:

bootstrap(Application, []);

But only if I change my bootstrap, I can run the code..

bootstrap(Application, [httpInjectables]);

Any ideas why is this happening?
I mean, if I want my service component to be distributed to other applications, I need to add httpInjectables to bootstrap? Seems wrong... The idea of NG2 was to build scalable and independent components.


Problem 2

If I request a non existing resource (it also happens locally):
image

The status body id correct, but the status code is not and always returns 200.

Best regards,
Tiago Braga

Activity

  1. changed the title [-]Http Injectables[/-] [+]Http Requests and Http Injectables[/+] on Jul 16, 2015
  2. matanlurey commented on Jul 17, 2015

    @matanlurey
    Contributor

    You need to add HTTP injectables, because Angular can't possibly know what you intend to use across your application. For example, you may use a 3rd party HTTP or Router solution.

    The second issue looks legit. @alxhub

  3. PatrickJS commented on Jul 17, 2015

    @PatrickJS
    Contributor

    the first problem is due to appInjector(boostrap bindings) vs viewInjector vs hostInjector

    the second problem might be solved with #2667 and #2882

  4. tbragaf commented on Jul 17, 2015

    @tbragaf
    Author

    Thank you both for replying!
    About the httpInjectables: imagine i have an application that does not need http requests, and you have a component that I found very useful, I would like to had the component, but that component of yours uses http.
    Again, i should only importante your component, nothing more.. But that's my opinion..

    Still, gonna close this.

    Best regards,
    Tiago Braga

  5. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  6. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions