1. cdk 文档 https://material.angular.io/cdk/categories
2. Coercion 模块提供了一些类型转换的工具。
import {
_isNumberValue,
coerceArray,
coerceBooleanProperty,
coerceCssPixelValue,
coerceNumberProperty
} from "@angular/cdk/coercion";
coerceNumberProperty(10.5); // 10.5 console.log("是否是number类型: " + coerceNumberProperty(‘a‘, ()=>‘不是‘)); // 第二参数是转换为 number 时的回调 console.log("是否是number类型: " + _isNumberValue(‘a‘));
coerceBooleanProperty(‘false‘); // false
coerceArray(1204) // [1024]
coerceCssPixelValue(‘10‘); // ‘10px‘
coerceStringArray(null); // [] // null ---> [] // [null] ---> ["null"] // ["a", "b ", " "] ---> ["a", "b"] // [1, [2, 3]] ---> ["1", "2,3"] // [{ a: 0 }] ---> ["[object Object]"] // { a: 0 } ---> ["[object", "Object]"]
1
【angular2】@angula/cdk/coercion 学习01
原文:https://www.cnblogs.com/tianxiaxuange/p/14415410.html