Reactive UIs with Angular 2.0

var statement = "she sells six sea shells on the sea shore";
var occurrenceCount = 0;
var words = [];
// split statement into words
var word = ""
for (var i = 0; i < statement.length; i++) {
if(statement[i] !== " ") {
word += statement[i];
} else {
words.push(word);
word = "";
}
}
// calculate the count
for (var i = 0; i < words.length; i++) {
if(words[i] === "sea") {
occurrenceCount++;
}
}
console.log(occurrenceCount);
var statement = "she sells six sea shells on the sea shore";
var count = statement
.split(" ")
.map(word => (word.match(/sea/g) || []).length)
.reduce((prev, curr) => prev + curr);
console.log(count);
RX = Observables + LINQ + Schedulers
// ng1 javascript
var getOpenIssuesCount = function(projectName) {
var url = 'https://api.github.com/repos/angular/' + projectName + '/issues?state=open';
var deferred = $q.defer();
$http.get(url).then(function(res) {
deferred.resolve(res.data.length);
});
return deferred.promise;
};
// ng2 typescript
getOpenIssuesCount(projectName: string) {
var url = 'https://api.github.com/repos/angular/' + projectName + '/issues?state=open';
return this.http
.get(url)
.map(res => res.json().length);
};
// ng1 javascript
var aggregateIssueCount = 0,
promises = [],
p1 = getOpenIssuesCount("angular"),
p2 = getOpenIssuesCount("material2"),
p3 = getOpenIssuesCount("angular-cli");
promises.push(p1);
promises.push(p2);
promises.push(p3);
p1.then(function(numIssues) {
aggregateIssueCount += numIssues;
});
p2.then(function(numIssues) {
aggregateIssueCount += numIssues;
});
p3.then(function(numIssues) {
aggregateIssueCount += numIssues;
});
$q.all(promises).then(function() {
$scope.count = aggregateIssueCount;
});
// ng2 typescript
var angularIssueSource = this.getOpenIssuesCount("angular");
var materialIssueSource = this.getOpenIssuesCount("material2");
var angularCliIssueSource = this.getOpenIssuesCount("angular-cli");
angularIssueSource
.merge(materialIssueSource)
.merge(angularCliIssueSource)
.reduce((x, y) => x + y)
.subscribe(function(x) {
self.count = x as number;
});

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store