【问题标题】:Can I debug AngularJS and TypeScript in Eclipse?我可以在 Eclipse 中调试 AngularJS 和 TypeScript 吗?
【发布时间】:2014-09-02 06:44:13
【问题描述】:

我刚刚开始使用 TypEcs,我正在尝试在 Typescript 和 AngularJS 中创建一个网页,我想在 Eclipse 中进行调试。

  • 是否可以在 Eclipse 中调试 TypeScript 和 Angular 页面?如果是这样,那么您能指导我正确的方向吗?

我尝试使用 TypeScript Standalone 选项调试单个打字稿文件,它可以工作。但我也想使用 AngularJS。我创建了一个 index.html 文件和一个 app.ts 文件,我还将 angular.d.ts 和 angular.min.js 等导入到脚本文件夹中。 我可以通过使用任何 TypEcs TypeScript 调试器来做到这一点吗?我尝试运行它,但在 var app = angular.module... 出现错误(ReferenceError: angular is not defined)。

我的猜测是我在索引文件中链接到的 angular.min.js 文件尚未加载。是因为 app.ts 设置为 TypeScript Standalone 配置中的主文件吗? (我无法选择 index.html)和/或我是否缺少一些代码/设置?

我希望你能帮助我。 提前谢谢!

下面是一些示例代码: index.html:

<html ng-app="helloworld">
<head>
    <title>Hello World!</title>
</head>

<body>
    <div class="container" ng-controller="HelloWorldCtrl">
        <input type="text" class="form-control" value="{{message}}" />
    </div>
    <script src="../scripts/angular.min.js"></script> 
    <script src="app.js"></script>
</body>
</html>

app.ts:

/// <reference path="../scripts/typings/angularjs/angular.d.ts"/>
module Sample.HelloWorld {

    export interface IHelloWorldScope extends ng.IScope {
        message: string;
    }

    export class HelloWorldCtrl {

        static $inject = ["$scope"];
        constructor(private scope: IHelloWorldScope) {
            scope.message = "Hello World";
        }
    }

    var app = angular.module("helloworld",["ui.bootstrap"]);
    app.controller("HelloWorldCtrl", HelloWorldCtrl);
}

【问题讨论】:

标签: eclipse angularjs typescript


【解决方案1】:

正如 Basarat 提到的,可以使用 TypEcs 中包含的“TypeScript Web Remote”调试选项

如何调试页面:

  1. 关闭所有打开的 chrome 窗口。
  2. 使用命令 chrome.exe --remote-debugging-port=9222 再次打开 Chrome
  3. 根据“为 WebKit 远程模式添加 TypeScript 调试”应用调试配置 TypEcs / 2.0 - New and Noteworthy
  4. 从第 1 点开始在 chrome 窗口中打开您的起始页 (index.html)。
  5. 进入调试视图
  6. 使用第 3 步中的配置进行调试
  7. 会出现一个对话框,您需要在其中选择要调试的文件所在的选项卡。
  8. 现在您可以单步调试代码并向 app.ts 文件添加断点(如果您愿意)。 (如果您没有看到步骤选项,请单击主线程)

如果您收到“无法获取用于调试的选项卡连接超时”错误,请关闭所有 chrome 窗口并使用 chrome.exe --remote-debugging-port=9222 命令重新打开 chrome。

【讨论】:

    【解决方案2】:

    我尝试使用 TypeScript Standalone 选项调试单个打字稿文件,它可以工作。但我也想用AngularJS

    步骤与独立相同。您应该启用源映射。

    ReferenceError: 角度未定义

    angular.min.jsscript 标记有问题 检查文件系统和/或浏览器网络请求。

    参见:webkit 远程调试https://bitbucket.org/axmor/typecs/wiki/2.0%20-%20New%20and%20Noteworthy

    【讨论】:

    • 感谢 basarat 的回复。现在它在使用远程调试选项时工作。我打开了另一个 chrome 窗口,我显然需要在运行 chrome.exe --remote-debugging-port=9222 之前关闭它,或者当我尝试调试它时出现错误“无法获取用于调试连接超时的选项卡”。虽然我在独立模式下仍然遇到同样的错误,但我想我不应该使用它。再次感谢您
    猜你喜欢
    • 2023-03-28
    • 2014-02-28
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    • 2016-03-08
    • 2023-04-02
    • 1970-01-01
    • 2012-01-13
    相关资源
    最近更新 更多