zoukankan      html  css  js  c++  java
  • 【angular2】@angula/cdk/coercion 学习01

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

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

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

    (1)转换为 number

    • coerceNumberProperty(10.5); // 10.5
      
      console.log("是否是number类型: " + coerceNumberProperty('a', ()=>'不是')); // 第二参数是转换为 number 时的回调
      console.log("是否是number类型: " + _isNumberValue('a'));

    (2)转换为 boolean

    • coerceBooleanProperty('false'); // false

    (3)转换为 array

    • coerceArray(1204) // [1024]

    (4)转换为 CSS pixel value

    • coerceCssPixelValue('10'); // '10px'

    (6)转换为 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]"]

    (7)转换为 coerceElement

    • coerceElement(1); // 1

     

    --------小尾巴 ________一个人欣赏-最后一朵颜色的消逝-忠诚于我的是·一颗叫做野的心.决不受人奴役.怒火中生的那一刻·终将结束...
  • 相关阅读:
    8.18学习日志
    8.17学习日志
    8.15学习日志
    8.14学习日志
    8.13学习日志
    8.12学习日志
    8.11学习日志
    kindle
    xcode 4 安装cocos2d-x 2.1.4
    GUI之CCControlExtension
  • 原文地址:https://www.cnblogs.com/tianxiaxuange/p/14415410.html
Copyright © 2011-2022 走看看