因此,当我想在 Angular 组件的 html 中声明一个新方法时,webstorm 为我提供了在 ts 中创建此方法的机会:
但是,如果我在 VS 代码中尝试相同的方法,则无法创建方法。
有什么解决办法吗? (扩展,也许是设置中的东西)
最佳答案
您可以使用扩展名 My Code Actions v0.6.0。
将此添加到您的 settings.json
"my-code-actions.actions": {
"[html]": {
"Create function {{atCursor:$1}}": {
"file": "${fileBasenameNoExtension}.ts",
"atCursor": "\\(click\\)=\"([^\"]+)\\(\\)\"",
"text": "function {{atCursor:$1}}() {\n}\n\n"
}
}
}
如果需要,您可以添加更复杂的(多个)编辑您可以查看扩展的文档页面,以查看添加/修改导入语句的复杂编辑示例。
如果 angular 模板文件不是 html,则调整 languageID
关于angular - VS Code - 如何从 angular html 模板创建方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65971560/