Is there any equivalent function in angular 2 as angular.isDefined
as in angular 1
Checked The safe navigation operator ?.
which only supports in tempalte
You can use getter function or get accessor to act as watch on angular 2.
Means safe navigation operator. From Docs. The Angular safe navigation operator (?.) is a fluent and convenient way to guard against null and undefined values in property paths.
Typescript does NOT have a function to check if a variable is defined, neither does Angular2.
Using a juggling-check, you can test both null and undefined in one hit:
if (object.property == null) {
If you use a strict-check, it will only be true for values set to null and won't evaluate as true for undefined variables:
if (object.property === null) {
no
angular2 uses proper JavaScript. it moves away from angular specific language. that is one of its goals.
just do ..
if (something == null) { // the only exception where double equals is OK - checks for undefined or null
...
}
Typescript does have a !. operator which might be worth looking at, not exactly sure how it works but i think it is similar to ?.
you could use undefined
function getSchool(name: string, address?: string, pinCode?: string): string {
if (address == undefined) {
console.log('address not defined');
}
if (pinCode == undefined) {
console.log('pincode not defined');
}
}
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