It’s possible to use @ViewChild (also @ViewChildren and @ContentChild/Children) to query for components of different types using dependency injection.

In the example below we can use @ViewChildren(Base) to get instances of Foo and Bar.

abstract class Base {}

  selector: 'foo',
  providers: [{ provide: Base, useExisting: Foo }]
class Foo extends Base {}

  selector: 'bar',
  providers: [{ provide: Base, useExisting: Bar }]
class Bar extends Base {}

// Now we can require both types of components using Base.
@Component({ template: `<foo></foo><bar></bar>` })
class AppComponent {
  @ViewChildren(Base) components: QueryList<Base>;

继续阅读 30秒学会 Angular 片段 – Getting components of different types with ViewChild

Converts a comma-separated values (CSV) string to a 2D array.

Use Array.prototype.slice() and Array.prototype.indexOf('\n') to remove the first row (title row) if omitFirstRow is true.
Use String.prototype.split('\n') to create a string for each row, then String.prototype.split(delimiter) to separate the values in each row.
Omit the second argument, delimiter, to use a default delimiter of ,.
Omit the third argument, omitFirstRow, to include the first row (title row) of the CSV string.

继续阅读 30秒学会 JavaScript 片段 – CSVToArray

A hook that implements fetch in a declarative manner.

  • Create a custom hook that takes a url and options.
  • Use the React.useState() hook to initialize the response and error state variables.
  • Use the React.useEffect() hook to anychronously call fetch() and update the state varaibles accordingly.
  • Return an object containting the response and error state variables.

继续阅读 30秒学会 React 片段 – useFetch