2

加入这个简单的AngularJS控制器大量与Visual Studio的(DefinitelyTyped)AngularJS和打字稿问题

/// <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运行后我的解决方案时,我收到了大量关于Visual Studio的打字稿编译器错误的1.4.9,用于AngularJS 1.4+的DefinitelyTyped angular.d.ts和用Resharper 9.0 Update 1的Visual Studio Community 2015.我的项目的Typescript工具在1.7上,编译器瞄准ES3以实现IE8的兼容性。

错误类似于400以上,95%来自jquery.d.ts。都是不同的,其中之一是“找不到名字布尔”。

我有问题,也使用NG,IAngularStatic,...的iScope所以我只是避免他们

回答

2

如果您的NuGet安装d.ts包,你可能已经安装了一个旧的jQuery的依赖。更新jQuery.d.ts nuget包,你应该是金色:)