【发布时间】:2023-03-14 22:53:01
【问题描述】:
我正在尝试为 Angular 1.7.8 的 DefinitelyType 的最新 Angular 和 Angular-Route 使用 Typescript 定义。
我更喜欢 Angular 1 而不是 2。
我正在尝试在没有任何模块加载器或包管理器等的情况下在 Visual Studio 2019 中设置 TypeScript。我刚刚将 .d.ts 文件添加到 /scripts/typings 中。
我有 2 个文件,app.module.ts 和 app.route.ts。 app.module.ts 没有错误,生成一个js文件。
我的 app.route.ts 文件如下所示:
/// <reference path="typings/angular/angular.d.ts" />
/// <reference path="typings/angular/angular-route.d.ts" />
module MyApplication
{
"use strict";
function routes($routeProvider: ng.route.IRouteProvider)
{
$routeProvider
.when("/home", {
templateUrl: "/scripts/app/home/home.html"
})
.otherwise({
redirectTo: "/home"
});
}
routes.$inject = ["$routeProvider"]
angular
.module("MyApplication")
.config(routes);
}
但是我看到这个错误并且没有生成 app.route.js 文件:
Namespace 'angular' has no exported member 'route'.
因为我没有使用模块加载器,所以我必须在 angular-route.d.ts 中注释掉这一行:
import * as angular from 'angular';
所以我不确定这是否会破坏任何东西。
为什么 ng.route 没有解析并给出错误?
如果我的 app.route.ts 文件实际上是使用 TypeScript 而不仅仅是常规的 Javascript 实现的,我也不介意 cmets(我知道 js = ts,但也许使用 ts 它可以/应该不同)。
感谢任何帮助。
【问题讨论】:
标签: angularjs visual-studio typescript