[英]VS Code - How to create a method from angular html template?
So, when I want to declare a new method in html of Angular component, WebStorm provides me opportunity to create this method in ts:因此,当我想在 Angular 组件的 html 中声明一个新方法时,WebStorm 为我提供了在 ts 中创建此方法的机会:
But, if I try same at VS code I can't create a method.但是,如果我在 VS 代码中尝试相同的方法,我将无法创建方法。 Is there some solution?有什么解决办法吗? (extensions, maybe something in settings) (扩展,也许在设置中)
You can use the extension My Code Actions v0.6.0.您可以使用扩展程序My Code Actions v0.6.0。
Add this to your settings.json
将其添加到您的settings.json
"my-code-actions.actions": {
"[html]": {
"Create function {{atCursor:$1}}": {
"file": "${fileBasenameNoExtension}.ts",
"atCursor": "\\(click\\)=\"([^\"]+)\\(\\)\"",
"text": "function {{atCursor:$1}}() {\n}\n\n"
}
}
}
You can add more complex (multiple) edits if needed如果需要,您可以添加更复杂(多个)的编辑
You can have a look at the doc page of the extension to see an example of a complex edit to add / modify an import statement.您可以查看扩展的文档页面,查看添加/修改导入语句的复杂编辑示例。
Adjust the languageID
if Angular template files are not html.如果 Angular 模板文件不是 html,请调整languageID
。
This is now possible with the VSCode Angular Language Service plugin v14.2.0现在可以使用VSCode Angular 语言服务插件v14.2.0
So, when I want to declare a new method in html of Angular component, webstorm provides me opportunity to create this method in ts:因此,当我想在 Angular 组件的 html 中声明一个新方法时,webstorm 为我提供了在 ts 中创建此方法的机会:
But, if I try same at VS code I can't create a method.但是,如果我在 VS 代码上尝试相同,我将无法创建方法。 Is there some solution?有什么解决办法吗? (extensions, maybe something in settings) (扩展,可能在设置中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.