gpt4 book ai didi

javascript - 使用 AngularJS 进行 Visual Studio Code 调试

转载 作者:数据小太阳 更新时间:2023-10-29 04:10:23 26 4
gpt4 key购买 nike

我想用新的 Visual Studio Code 调试我的 Angular 应用程序,但 Angular 和 Visual Studio Code 似乎有问题..

这是我的 launch.json:

{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Manager",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "/Volumes/Transcend/WorkArea/Manager/app/app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArguments": [],
// Environment variables passed to the program.
"env": { },
// Use JavaScript source maps (if they exist).
"sourceMaps": false
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858,
"sourceMaps": false
}
]
}

当我尝试调试我的 Angular 应用程序时出现此错误,

错误:

ReferenceError: angular is not defined
at Object.<anonymous> (/Volumes/Transcend/WorkArea/Manager/app/app.js:1:79)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain [as _onTimeout] (module.js:497:10)
at Timer.listOnTimeout [as ontimeout] (timers.js:112:15)
MacBook-Pro:Manager user$ cd '/Volumes/Transcend/WorkArea/Manager'; 'node' '--debug-brk=55539' '/Volumes/Transcend/WorkArea/Manager/app/app.js'
debugger listening on port 55539

Killed: 9

应用程序.js

/// <reference path="../typings/angularjs/angular.d.ts"/>

var routerApp = angular.module('uiRouter', ['ui.router', 'uiRouter.dmvs']);

routerApp.config(function($stateProvider, $urlRouterProvider) {

$urlRouterProvider.otherwise('/home');

$stateProvider

.state('home', {
url: '/home',
templateUrl: 'app/dmvs/partial-d.html',
controller:'dController'
})

});

最佳答案

好的,在@code 人员的帮助下,我让它工作了。我现在可以从 IDE 中完全调试 Angular 客户端了!希望这会帮助其他人...

首先,您需要下载“Debugger for Chrome Extension”。您可以通过键入以下内容来执行此操作:

F1
ext Install Extensions
debug (then select Debugger For Chrome)

安装完成后,我使用了此处的 MSFT 说明:

https://marketplace.visualstudio.com/items/msjsdiag.debugger-for-chrome

我只能使用“attach”方法,所以我在 Chrome 中使用它。这是我使用的 launch.son 文件的最终版本:

{
"version": "0.2.0",
"configurations": [
{
// Use this to get debug version of Chrome running:
// /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
"name": "Attach",
"type": "chrome",
"request": "attach",
"port": 9222,
"webRoot": "./www"
}
]
}

此外,不要忘记用这个(对于 Mac)以 Debug模式启动 Chrome:

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222

伟大的编辑器@code!

OBS:不要忘记杀死这里提到的所有 Chrome 实例:https://github.com/Microsoft/vscode-chrome-debug/issues/111#issuecomment-189508090

关于javascript - 使用 AngularJS 进行 Visual Studio Code 调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31075856/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com