【问题标题】:Lots of problems with AngularJS and Typescript on Visual Studio (DefinitelyTyped)Visual Studio 上的 AngularJS 和 Typescript 存在很多问题(DefinitelyTyped)
【发布时间】:2016-05-15 15:23:25
【问题描述】:

在添加这个简单的 AngularJS 控制器后运行我的解决方案时,我在 Visual Studio Typescript 编译器上遇到很多错误

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

"use strict";

class ProgressBarController {
    static $inject: Array<string> = ["$rootScope", "$element"];
    static measure = "px";
    static startPageFactor = 1;
    static endPageFactor = 1;

    private rootScope; // todo define RootScope boilerplate
    private element: JQuery;

    constructor($rootScope, $element: JQuery) {
        this.rootScope = $rootScope;
        this.element = $element;
    }

    getWidth(): string {
        var self = ProgressBarController,
            masterBarWidth = parseFloat(this.element.css("width").split(self.measure)[0]),
            totalPages = this.rootScope.app.pages.length - self.endPageFactor,
            eachPageProgress = (masterBarWidth / totalPages),
            currentPage = this.rootScope.app.currentIndex(),
            progress = eachPageProgress * (currentPage - self.startPageFactor);

        return progress + self.measure;
    }
}

angular.module("myDirectives")
    .controller("progressBarController", ProgressBarController);

我正在使用 AngularJS 1.4.9,AngularJS 1.4+ 和 Visual Studio Community 2015 使用 AngularJS 1.4.9,DefinitelyTyped angular.d.ts 和 Resharper 9.0 更新 1。我项目的 Typescript 工具在 1.7 上,编译器的目标是 ES3 IE8 兼容性。

错误超过 400 个,95% 来自 jquery.d.ts。都是不同的,其中之一是“找不到名称 bool”。

我在使用 ng、IAngularStatic、IScope 时也遇到了问题......所以我只是避免使用它们

【问题讨论】:

    标签: javascript angularjs typescript visual-studio-2015 definitelytyped


    【解决方案1】:

    如果您从 NuGet 安装了 d.ts 包,您可能安装了旧的 jQuery 依赖项。更新 jQuery.d.ts nuget 包,你应该是金子 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-24
      • 2023-03-21
      • 2018-06-10
      • 2020-07-04
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 1970-01-01
      相关资源
      最近更新 更多