This was very helpfull, but I'm having problems with the "provide()"
keyword. How did you make this compile? vs2015 complains with a "TS2304:
Cannot find name 'provide'" when I add the statement to my
bootstrap(AppComponent...) method.
I'm using angular2 beta9.
Thanks for any help
Snorre
On Friday, January 15, 2016 at 10:41:07 PM UTC+1, Sam A wrote:
>
> Thanks for posting this Martin! Today is my first day with Angular2 so I
> was having a bit of trouble understanding some of the concepts involved
> here. Could be a problem others will have as well, so I'm posting the
> process I went through. There could be some bad assumptions (?) but this is
> working in my project right now.
>
> Originally following along with the Angular2 5 minute demo. I had
> bootstrapped my app like this;
>
> bootstrap(AppComponent);
>
>
> I had to add the HTTP_PROVIDERS as a provider before I could make a
> request using http.get.
>
> @Component({
>> selector: 'my-app',
>> templateUrl: 'app/app.component.html',
>> providers: [HTTP_PROVIDERS],
>> })
>
>
> This resulted in a successful round trip (to our MS web.api server with
> Access-Control-Allow-Credentials: true). Of course without any credentials
> in the request the response was:
>
> HTTP/1.1 401 Unauthorized
>
>
> Following along with Martin's code, I'd added the definition for
> CORSBrowserXHr in my boot.ts file and also eventually found out you could
> provide the injections as well:
>
> bootstrap(AppComponent,
>> [
>> HTTP_PROVIDERS,
>> provide(BrowserXhr, { useClass: CORSBrowserXHr }),
>> ]);
>
>
> Tried the request again and.. no luck:
>
> HTTP/1.1 401 Unauthorized
>
>
> Eventually realized that I was replacing the HTTP_PROVIDERS within my own
> class. Updated the class definition to look like this:
>
> @Component({
>> selector: 'my-app',
>> templateUrl: 'app/app.component.html',
>> })
>
>
> I tried again and.. success:
>
> HTTP/1.1 200 OK
>
>
> Good luck!
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.