I don't know if this syntax or symbol or whatever belongs to Angular2
or something else...
but I wonder with,
what ...
syntax is and how it works behind the scene?
ngOnChanges(...args:any[])
{
console.log(args);
}
HTML is the language of the Angular template.
The exclamation mark ! tells, that the field is non-null non-undefined (see Microsoft's TypeScript documentation).
The template can change the value of the data-bound class property and the class can change the value of the property in the template. The template and the class are bound to each other, any change in either of them results in data updates in both of them. Example import { Component } from '@angular/core';@Component({
An operator is a pure function which takes in observable as input and the output is also an observable. To work with operators we need a pipe() method.
It's the TypeScript rest operator. In this case, it means any number of arguments of any type can occur there; the function will see them as an array of any
. (JavaScript recently got rest and spread operators as well, as of ES2015, but the :any[]
in your example tells us this is TypeScript.)
E.g.:
ngOnChanges('a', 42, null);
...would show
["a", 42, null]
in the console.
Here's a complete example (live copy):
function foo(...args:any[]) {
console.log("args.length = " + args.length);
args.forEach((arg:any, index:Number) => {
console.log("args[" + index + "]: " + arg);
});
}
foo('a', 42, null);
outputs
args.length = 3 args[0]: a args[1]: 42 args[2]: null
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With