首页 > 其他 > 详细

【angular2】@angula/cdk/coercion 学习01

时间:2021-02-19 13:27:52      阅读:20      评论:0      收藏:0      [点我收藏+]

1.  cdk 文档 https://material.angular.io/cdk/categories

2. Coercion 模块提供了一些类型转换的工具。

  • import {
        _isNumberValue,
        coerceArray,
        coerceBooleanProperty,
        coerceCssPixelValue,
        coerceNumberProperty
    } from "@angular/cdk/coercion";

  • 转换为 number
  • coerceNumberProperty(10.5); // 10.5
    
    console.log("是否是number类型: " + coerceNumberProperty(‘a‘, ()=>‘不是‘)); // 第二参数是转换为 number 时的回调
    console.log("是否是number类型: " + _isNumberValue(‘a‘));
  • 转换为 boolean
  • coerceBooleanProperty(‘false‘); // false
  • 转换为 array
  • coerceArray(1204) // [1024]
  • 转换为 CSS pixel value
  • coerceCssPixelValue(‘10‘); // ‘10px‘
  • 转换为 string array
  • 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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!