Skip to content

Instantly share code, notes, and snippets.

@rhencke
Last active September 18, 2015 04:25
Show Gist options
  • Save rhencke/070fa9d114f9fde849ae to your computer and use it in GitHub Desktop.
Save rhencke/070fa9d114f9fde849ae to your computer and use it in GitHub Desktop.
/// <reference path="./typings/angular2/angular2.d.ts" />
/// <reference path="./typings/node/node.d.ts" />
/// <reference path="./typings/rx/rx-lite.d.ts" />
import {Component, View, Injectable, bootstrap, ChangeDetectionStrategy} from 'angular2/angular2';
import * as proc from 'child_process';
@Injectable()
class MyService {
val: string;
constructor() {
this.val = "nothing yet"
var self = this;
// This runs, but fires no change event when val is changed.
proc.exec("false", (err, stdout, stderr) => {
self.val = "ran false";
});
// This runs and DOES fires a change event when val is changed.
window.setTimeout(() => {
self.val = "timeout returned;"
}, 1000);
}
}
@Component({
selector: 'my-component',
viewBindings: [MyService]
})
@View({
template: '<h1 id="output">My First Angular 2 App: {{_svc.val}}</h1>'
})
class MyComponent {
private _svc: MyService;
constructor(svc: MyService) {
this._svc = svc;
}
}
bootstrap(MyComponent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment