在angular6中引入string的prototype方法
2018-08-30 17:23
344 查看
在使用angular6,有使用到这个js库:https://github.com/tmaeda1981jp/string-format-js
主要使用其中类似'This is a %s'.format('pen') === 'This is a pen'的方法。
但在引入该js后,直接在ts中对string使用该format方法,会报如下错误:
最终在网上查找相关的解决方案:
在typing.d.ts增加如下声明:
之后在ts中针对string变量使用format方法就正常了。
主要使用其中类似'This is a %s'.format('pen') === 'This is a pen'的方法。
但在引入该js后,直接在ts中对string使用该format方法,会报如下错误:
ERROR in src/app/routes/openstack/overview.component.ts(193,75): error TS2339: Property 'format' does not exist on type '"up{node_type=\"%s\",component=\"node\"}"'
最终在网上查找相关的解决方案:
在typing.d.ts增加如下声明:
interface String{ format:any }
之后在ts中针对string变量使用format方法就正常了。
相关文章推荐
- Object.prototype.toString.call()方法
- JS中string方法中常用方法之五:String.prototype.slice()
- JS中string方法中常用方法之十一:String.prototype.toLocaleUpperCase()
- JavaScript:Object.prototype.toString方法的原理--紫云妃
- Object.prototype.toString.call()方法浅谈
- 判断js中各种数据的类型方法之typeof与0bject.prototype.toString讲解
- JS中string方法中常用方法之十二:String.prototype.toLowerCase()和String.prototype.toUpperCase()
- js中通过Object.prototype.toString方法----精确判断对象的类型
- 判断js中各种数据的类型方法之 typeof() 和 Object.prototype.toString() 详解
- JavaScript:Object.prototype.toString方法的原理
- JS中string方法中常用方法之六:String.prototype.substring()
- String.prototype.slice() 方法
- js中通过Object.prototype.toString方法----精确判断对象的类型
- JS常用方法--String.prototype使用!
- JavaScript中toStirng()与Object.prototype.toString.call()方法浅谈
- js中通过Object.prototype.toString方法----精确判断对象的类型
- 数组Array和字符串String的indexOf方法,以及ES7(ES2016)中新增的Array.prototype.includes方法
- JS中string方法中常用方法之三:String.prototype.charCodeAt()
- Object.prototype.toString.call()方法浅谈
- Object.prototype.toString.call()方法浅谈