Extension methods in typescript (system)

后端 未结 2 1148
无人及你
无人及你 2021-02-07 08:50

In my angular2 project I\'m trying to extend the prototype of the string class using typescript. This is my code:

interface String 
{
    startsWith(s:         


        
2条回答
  •  盖世英雄少女心
    2021-02-07 09:24

    Instead of importing the code in html just put this at the top of your code:

    import './utils/extensions';
    

    Just replace it with your path to the file.

    Here are some more resources on modules and imports:

    TypeScript docs

    MDN docs

提交回复
热议问题