Last active
September 18, 2015 04:25
-
-
Save rhencke/070fa9d114f9fde849ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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