This file contains hidden or 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
@Component({ | |
selector: 'video-list', | |
templateUrl: 'video-list.html' | |
}) | |
class VideoList implements OnInit { | |
@Input() Videos:video[] ; | |
@Output() clickParentChange = new EventEmitter(); | |
ngOnInit(){ |
This file contains hidden or 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
request(url: string | Request, options?: RequestOptionsArgs): Observable<Response>; | |
/** | |
* Performs a request with `get` http method. | |
*/ | |
get(url: string, options?: RequestOptionsArgs): Observable<Response>; | |
/** | |
* Performs a request with `post` http method. | |
*/ | |
post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response>; | |
/** |
This file contains hidden or 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
@Injectable() | |
export class CommentService { | |
// Resolve HTTP using the constructor | |
constructor (private http: Http) {} | |
// private instance variable to hold base url | |
private commentsUrl = 'http://localhost:3000/api/comments'; | |
} | |
getComments() : Observable<Comment[]> { | |
// ...using get request | |
return this.http.get(this.commentsUrl) |
This file contains hidden or 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
// Add a new comment | |
addComment (body: Object): Observable<Comment[]> { | |
let bodyString = JSON.stringify(body); // Stringify payload | |
let headers = new Headers({ 'Content-Type': 'application/json' }); // ... Set content type to JSON | |
let options = new RequestOptions({ headers: headers }); // Create a request option | |
return this.http.post(this.commentsUrl, body, options) // ...using post request | |
.map((res:Response) => res.json()) // ...and calling .json() on the response to return data | |
.catch((error:any) => Observable.throw(error.json().error || 'Server error')); //...errors if any | |
} |
This file contains hidden or 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
import {Injectable} from '@angular/core'; | |
import {Http, Headers, Response, Request, BaseRequestOptions, RequestMethod, ResponseContentType} from '@angular/http'; | |
import {Observable} from 'rxjs/Rx'; | |
@Injectable() | |
export class HttpClient { | |
constructor(private http: Http) {} | |
post(url: string, body: any = {}) { | |
return this.request(url, RequestMethod.Post, body); | |
} |
This file contains hidden or 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
@Injectable() | |
export class cartService { | |
constructor(private httpclient : HttpClient) {} | |
private cartSubject = new Subject<CartState>(); | |
Products : product[]= []; | |
CartState = this.cartSubject.asObservable(); | |
addProduct(_product:any) { | |
console.log('in service'); | |
this.Products.push(_product) | |
this.cartSubject.next(<CartState>{loaded: true, products: this.Products}); |
This file contains hidden or 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
export default class shoppingCartItem { | |
@Input()product : product; | |
constructor(private _cartService : cartService) {} | |
AddProduct(_product : product) { | |
_product.added = true; | |
this | |
._cartService | |
.addProduct(_product); | |
} | |
RemoveProduct(_product : product) { |
This file contains hidden or 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
export default class shoppingList { | |
loaded : boolean = true | |
products : product[]; | |
private subscription : Subscription; | |
constructor(private _cartService : cartService) {} | |
ngOnInit() { | |
// this.loaderService.show(); | |
this.subscription = this._cartService.CartState | |
.subscribe((state : CartState) => { | |
this.products = state.products; |
This file contains hidden or 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
var quizQuestions = [ | |
{ | |
question: "What franchise would you rather play a game from?", | |
answerindex : 1, | |
answers: [ | |
{ | |
type: "IBM", | |
content: "Halo", | |
answer : false | |
}, |
This file contains hidden or 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
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
counter: 0, | |
questionId: 1, | |
question: '', | |
answerOptions: [], |