Search code examples
visual-studio-codecode-snippetsvscode-snippets

VSCode snippet for importing Angular Material Modules


I would like to create a snippet tom import an angular material module like so

import { MatToolbarModule } from "@angular/material/toolbar";
etc.

This is what i have done so far:

"Import Angular Material Modules": {
        "prefix": "ng-mat-import",
        "body": [
            "import { Mat${1}Module } from '@angular/material/${1/(.*)/downcase/$1}'",
        ]
    },

I can't find out what is missing and what is going wrong. The VSCode Documentation is so vague.

The result i would like to get is something like what the answers in Visual studio code: replace char case while typing in snippet does


Solution

  • Just a couple of things incomplete in the transform syntax:

    "import { Mat${1}Module } from \"@angular/material/${1/(.*)/${1:/downcase}/}\";",

    I also used \" to include double quotes as your desired end result seems to indicate you want instead of single quotes. If you just want single quotes there is no need to escape those.

    "import { Mat${1}Module } from '@angular/material/${1/(.*)/${1:/downcase}/}';",