Decorators

This commit is contained in:
Max Lynch
2015-04-28 14:05:51 -05:00
parent 08a5fd9fad
commit acbafd4fce
8 changed files with 119 additions and 43 deletions

View File

@@ -168,6 +168,8 @@ class IonicApp {
nav.push(PostDetail, data);
})
route.otherwise('/login');
}, 200);
}
}

View File

@@ -0,0 +1,5 @@
<ion-view [view-title]="post.title">
<ion-content>
<h2>SINGLE</h2>
</ion-content>
</ion-view>

View File

@@ -0,0 +1,15 @@
import {For, Ancestor, Descendent, Parent, NgElement, Component, View as NgView, bootstrap} from 'angular2/angular2';
import {View, Content, Nav, NavPane, List, Item} from 'ionic/ionic';
import {HackerNews} from 'hn'
@Component({ selector: 'top-stories' })
@NgView({
templateUrl: 'pages/top.html',
directives: [View, Content, For, List, Item]
})
export class HNSinglePost {
constructor(@Parent() viewport: Nav) {//, @Ancestor() app: HNApp) {
console.log('SINGLE');
}
}

View File

@@ -2,7 +2,7 @@
<ion-content>
<!--<h1>That's so <i>HACKER NEWS</i></h1>-->
<ion-list>
<ion-item *for="#story of stories">
<ion-item *for="#story of stories" push-to="single">
{{story.title}}
</ion-item>
</ion-list>

View File

@@ -1,19 +1,31 @@
import {For, Ancestor, Descendent, Parent, NgElement, Component, View as NgView, bootstrap} from 'angular2/angular2';
import {View, Content, Nav, NavPane, List, Item} from 'ionic/ionic';
import {PushToNav, View, Content, Nav, NavPane, List, Item} from 'ionic/ionic';
import {HackerNews} from 'hn'
@Component({ selector: 'top-stories' })
@NgView({
templateUrl: 'pages/top.html',
directives: [View, Content, For, List, Item]
directives: [View, Content, For, List, Item, PushToNav]
})
export class HNTopStories {
constructor(@Parent() viewport: Nav) {//, @Ancestor() app: HNApp) {
console.log('TOP STORIES');
this.stories = [];
this.stories = [{
by: "FatalLogic",
descendants: 77,
id: 9444675,
//kids: Array[26]
score: 464,
text: "",
time: 1430116925,
title: "Under Pressure",
type: "story",
url: "http://minusbat.livejournal.com/180556.html"
}];
return;
var APIUrl = 'https://hacker-news.firebaseio.com/v0';
this.fb = new Firebase(APIUrl);
this.fb.child('topstories').limitToFirst(20).once('value', (snapshot) => {
@@ -27,6 +39,7 @@ export class HNTopStories {
this.fb.child("item").child(itemID).on('value', (data) => {
setTimeout(() => {
console.log(itemID, data.val());
console.log('ADDED');
this.stories.push(data.val());
});

View File

@@ -0,0 +1,25 @@
import {
Decorator,
View as NgView,
For,
NgElement,
Parent,
Ancestor
} from 'angular2/angular2';
import {Optional} from 'angular2/di'
import {Nav} from 'ionic/ionic';
@Decorator({
selector: '[push-to]'
})
export class PushToNav {
constructor(
element: NgElement,
@Ancestor() viewportNav: Nav
) {
console.log('PUSH TO NAV', element.domElement, viewportNav);
this.navTag = element.domElement.getAttribute('push-to');
console.log('PUSH TO NAV', this.navTag);
}
}