【发布时间】:2016-07-05 13:20:15
【问题描述】:
过去几年我一直在使用 ASP.NET,所以我很擅长使用 MVC、JavaScript、Visual Studio 等。
现在我有一个小项目需要处理。它是用 AngularJS 开发的。我已经安装了 Visual Studio Code,所以我可以启动和调试应用程序。我知道我需要创建一个 launch.json 文件,但是我不确定该文件中的内容。
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}\\manager\\angular\\js\\app.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}
app.js 文件
// Declare app level module
var main = angular.module('eng-im', [
'ngAnimate',
'ngRoute',
'ngCookies',
'toaster',
'ui.router',
'ui.bootstrap',
'angularSpinner',
'engrafa.directives',
'engrafa.controllers',
'rt.encodeuri',
'searchbar',
'base64'
]);
当我按下 F5 时,我看到调试器从“angular.module()”方法开始,但是当我单步执行它时会引发异常。
> node --debug-brk=40967 --nolazy manager\angular\js\app.js
Debugger listening on port 40967
c:\code\manager\angular\js\app.js:32
var main = angular.module('eng-im', [ ^
ReferenceError: angular is not defined
at Object.<anonymous> (c:\code\manager\angular\js\app.js:32:12)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.runMain [as _onTimeout] (module.js:442:10)
at Timer.listOnTimeout (timers.js:92:15)
问题
1)AngulerJs 应用程序有 app.js 文件和 index.html 文件。 launch.json 中“program”属性的值应该是多少?
2) 我需要为 AngularJS 安装任何扩展吗?
【问题讨论】:
-
运行 Angular 应用程序唯一需要做的就是提供加载 angular.js 库并启动应用程序的 html 文件。对本地服务器的任何其他请求都必须提供请求中调用的确切路径。您的方法的问题是您的 app.js 正在尝试使用尚未加载的脚本(角度)。
-
你需要包含实际的 AngularJS 库:github.com/angular/angular.js
-
该应用程序已经开发并在生产环境中运行了相当长的一段时间。这意味着我假设引用是正确的。我不确定其他开发人员使用了哪个 IDE。我试图使用 Visual Studio Code。 Windows中AngulerJS的首选IDE是什么
-
好的...所以您需要加载 index.html 文件而不是 app.js。但除此之外,vscode 启动的网络服务器需要能够正确传递 index.html 将尝试加载的文件。
标签: javascript angularjs npm visual-studio-code