Hi,

Can anyone please advise on this?

Thanks,

Martin

On Thursday, September 17, 2015 at 10:36:55 PM UTC+1, Martin Dickson wrote:
>
> Hi,
>
> I have an Angular 2 Component calling a service which returns data from an 
> HTTP request below.  The service returns data but the view part of the 
> component does not refresh.
>
> Service:
>
> // TypeScript
> import {Inject} from 'angular2/angular2';
> import {Http, HTTP_BINDINGS} from 'angular2/http';
> import {ROUTER_BINDINGS} from 'angular2/router';
>
>
> export class MyService {
>
> private http: Http;
> constructor(@Inject(Http) http:Http) { 
> this.http = http;
> }
>
> public getData(callback){
>
>     this.http.get('http://localhost:8080/data.json').toRx()
>                 .map((res) => res.json())
>                 .subscribe((data) => {
>                     callback(data);
>               });
>
> }
>
> }
>
>
> Component:
>
> // TypeScript
> import {Component, View, bootstrap, Inject, NgFor} from 
> 'angular2/angular2';
> import {Http, HTTP_BINDINGS} from 'angular2/http';
> import {ROUTER_BINDINGS} from 'angular2/router';
>
> import {MyService} from 'ts/my-service';
>
>
>
> @Component({
>   selector: 'my'
> })
> @View({
>   template: `
>   
>     <h1>{{dummy}}</h1>
>     
>   `,
>   directives: [NgFor]
> })
>
> export class MyComponent {
>   
>   dummy: String;
>
>   constructor(myService: MyService) {
>     
>     myService.getData(function(data){
>       console.log(data);
>       dummy = data.someText;   // THIS DOES NOT REFLECT IN THE VIEW
>       
>     })
>   }
>
> }
>
> How do I update the bound view variable "dummy" above?  Any help 
> appreciated.
>
> I am using Angular2 alpha37.
>
> Thanks,
>
> Martin
>
>

-- 
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 http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to