Returns all indexes of a given element in the collection, or [-1] if it is not present.

Use reflect.ValueOf() to get the array or slice and the value to search for, make() to create an appropriate slice.
Use a for loop with Value.Len() and Value.Index() to iterate over each element and compare it to the search value.
Use append() to add indexes of matching elements to the resulting slice.

继续阅读 30秒学会 Golang 片段 – IndexOfAll

It is possible to add global event listeners in your Components/Directives with HostListener. Angular will take care of unsubscribing once your directive is destroyed.

@Directive({
  selector: '[rightClicker]'
})
export class ShortcutsDirective {
  @HostListener('window:keydown.ArrowRight')
  doImportantThings() {
    console.log('You pressed right');
  }
}

继续阅读 30秒学会 Angular 片段 – Global event listeners

It is possible to use SVG tags in your Angular component, to create beautiful graphs and visualizations. There are 3 things you need to know:

  1. When binding an SVG attribute, use attr

    <circle [attr.cx]="x" [attr.cy]="y"></circle>
  2. When creating sub-components, use attribute and not tag selector:

    // Not: <child-component></child-component>
    <g child-component></g>
    @Component({selector: '[child-component]' })
  3. When using SVG tags in sub-components use svg prefix:

    @Component({
    selector: '[child-component]',
    template: `<svg:circle></svg:circle>`
    })

继续阅读 30秒学会 Angular 片段 – SVG