Binding events when using a ngForTemplate in Angular 2

Been looking for an answer to this for a week now and I finally came up with a pretty decent solution. Instead of using ngForTemplate I would suggest using ngTemplateOutlet. It is already described pretty well here: angular2 feeding data back to `<template>` from `[ngTemplateOutlet]` The custom template for the list items is placed between … Read more

Do we need to unsubscribe from observable that completes/errors-out?

The Subscribing and Unsubscribing section of the Observable Contract is definitive regarding your question. It states: When an Observable issues an OnError or OnComplete notification to its observers, this ends the subscription. Observers do not need to issue an Unsubscribe notification to end subscriptions that are ended by the Observable in this way. This is … Read more

Share data between components using a service in Angular2

camaron is right. Your mistake is that you declare UtilityService twice: Once in the providers of SearchComponent. Once in the providers of TransferComponent. You should declare the service ONLY ONCE to make sure both components get the same instance. For this you can choose between either of these options: Declare the service in the providers … Read more

Access Meta-Annotation inside Class (TypeScript)

With the new angular version, you should use the native Reflect object. No IE11 support though: const annotations = Reflect.getOwnPropertyDescriptor(MyModule, ‘__annotations__’).value; Read Jeff Fairley’s answer below on what to do with the data after that You can see an annotation/decorator as a normal function call. To this function the ‘Class/Function’ object (not instance) gets send … Read more

Autoscroll in Angular 2

update Currently there is no automatic way. See also Angular 2 typescript error when using subscribe function on new router (rc 1) See also https://github.com/angular/angular/issues/6595#issuecomment-244232725 class MyAppComponent { constructor(router: Router) { router.events.subscribe(s => { if (s instanceof NavigationEnd) { const tree = router.parseUrl(router.url); if (tree.fragment) { // you can use DomAdapter const element = document.querySelector(“#” … Read more

iframe inside angular2 component, Property ‘contentWindow’ does not exist on type ‘HTMLElement’

The template doesn’t exist in the DOM yet when the constructor is executed Use instead import { Component, ViewChild, ElementRef } from ‘@angular/core’; @Component({ moduleId: module.id, selector: ‘component-iframe’, template: ‘<iframe #iframe></iframe>’ }) export class ComponentIframe { @ViewChild(‘iframe’) iframe: ElementRef; ngAfterViewInit() { let content=”<button id=”button” class=”button” >My button </button>”; let doc = this.iframe.nativeElement.contentDocument || this.iframe.nativeElement.contentWindow; doc.open(); … Read more

Filtering specific column in Angular Material Table with filtering in angular?

You have to override the filterPredicate of your dataSource. Here’s an example of how to do it: Working demo Essentially, you want to specify what properties in your data the filter is applied to: this.dataSource.filterPredicate = function(data, filter: string): boolean { return data.name.toLowerCase().includes(filter) || data.symbol.toLowerCase().includes(filter) || data.position.toString().includes(filter); };