I have a simple angular2 (rc1) component which subscribes to a service. When the service updates the subscription, I can log the result in the component's subscription but the view isn't updated.
My initial suspicion was that my inner this
wasn't bound to the outer one, but I'm using a fat arrow on the subscribe
callback, and also tried the old let self = this
on the first line of the constructor and then doing self.SuccessMessage = result
to no avail.
Do I have to force the change detection somehow? Here's my component:
import {Component} from 'angular2/core';
import {Subscription} from 'rxjs/Subscription';
import {UploaderService} from './uploader.service';
@Component({
selector: 'aoma-uploader-status-mini',
providers: [],
viewProviders: [],
templateUrl: './app/uploader/mini-uploader-status.component.html'
})
export class MiniUploadStatusComponent {
subscription:Subscription;
successMessage:any = {};
constructor(private _uploaderService: UploaderService) {
// view correctly shows this value:
this.successMessage.serverMessage = 'before ';
this.subscription = _uploaderService.fileSuccess$.subscribe(result => {
// this fires and logs the result correctly:
console.log('the mini uploader: type of result', result);
// view is never updated here
this.successMessage = result;
})
}
}
Currently my view only has {{ successMessage | json }}
in it. Again it correctly displays the 'before' value, but doesn't change when the subscription gets the result object.