我为Angular 2 alpha 45构建了一个应用程序,它工作得很好,但我不得不花很多时间才能让它工作。我理解Angular 2,但我不知道如何使用Angular 2才能让它工作。
我正在尝试一个干净的'Angular 2: 5 min Quickstart'构建。有许多问题,我将尽可能具体。我想了解为什么会发生这些问题,并希望如何解决它们。Visual Studio 2015更新1,Typescript 1.7。
Typescript配置:快速入门包括一个tsconfig.json文件。
{
"compilerOptions": {
"target": "es5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
不过,我不确定这样做是否有用,因为我必须编辑ProjectName.csproj文件并添加行:<TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
以消除实验装饰器错误。https://github.com/Microsoft/TypeScript/issues/3124似乎建议tsconfig文件需要在/Scripts中才能工作,但这对我也不起作用。
我想知道如何让这个tsconfig文件工作,或者编辑.csproj文件以获得相同的编译器选项。如果您查看项目属性> Typescript Build。这些都很重要吗?模块系统应该是: System吗?
我的文件结构与Quickstart相同。
app/
app.component.ts
boot.ts
node_modules/
blah
index.html
tsconfig.json
package.json
我使用powershell运行npm install来获取node_modules目录中的所有内容。
import {Component} from 'angular2/core';
显示错误。../node_modules/angular2/core';
不会显示错误,但是当您构建项目时,在node_moduels/angular2/src/*
中的文件中会出现许多构建错误。现在,我也许能够进入并手动修复这些问题,但如果出现这些错误,我觉得配置是错误的。tsconfig似乎想要排除node_modules
。为什么我不能使用'angular2/core'
而必须使用它的相对路径?如果我在Visual Studio项目中包含node_modules,那么在node_modules
中会有大量的构建错误。另外:我之所以做这个干净的构建,是因为我不知道如何将项目从alpha 45更新到beta 0。在我的项目中修改Angular 2中的bug是很容易的,但是现在让应用程序加载所有的模块是不可能的。
下一部分是假设我克服了构建错误:在index.html
中有:
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
在没有指定文件扩展名的情况下,我从未让System.import('app/boot')
工作过。这是visual studio的问题还是.NET MVC的问题?如果我在index.html
中指定文件扩展名,那么在System.js尝试查找没有文件扩展名的组件文件时,我会得到404(即使配置有defaultExtension: 'js'
。这是因为我需要在我的项目中包含js文件吗?如果我解决了这个问题,我就得处理
system.src.js:1049 GET http://localhost:63819/angular2/http 404 (Not Found)
我没有遇到任何构建错误,但是现在System.js没有加载任何内容。
我觉得这些问题都是由不同的系统以不同的方式解释打字稿造成的。我觉得我说得不够清楚,但我不知道如何弄清楚这个问题。如果您能给予我任何帮助和指导,我将不胜感激。我觉得我已经在寻找这个问题的答案好几天了。
发布于 2015-12-19 22:41:25
我对asp.net 5 vnext和Angular 2的新特性总体上很满意,但是在Visual Studio中安装Angular 2是件麻烦的事情。我忠实地遵循了angular.io快速入门指南,但在使用以下代码之前,我没有幸运地运行Hello Angular 2应用程序:
<script src="~/lib/anguar2/angular2-polyfills.js"></script>
<script src="~/lib/es6-shim/es6-shim.js"></script>
<script src="~/lib/systemjs/system.js"></script>
<script>
System.config({
defaultJSExtensions: true
});
</script>
<script src="~/lib/rxjs/rx.js"></script>
<script src="~/lib/anguar2/angular2.min.js"></script>
<script>
System.import('js/boot');
</script>
我希望我能更好地理解为什么它能工作,而角度样板却不能,但至少我让它工作了。希望这能有所帮助。
发布于 2016-01-07 08:44:12
确保你是在Visual Studio 2015 Update 1,Typescript 1.7.*中,你也可以运行'Angular 2: 5 min Quickstart‘。
你作为VS2015的“外部web工具”的问题有太旧的版本
在VS 2015创建asp.net5网络应用程序后,单击显示所有文件,然后删除package.json和node_modules文件夹,并再次添加package.json。
如果以上内容不起作用,请查看以下内容:http://jameschambers.com/2015/09/upgrading-npm-in-visual-studio-2015/
https://stackoverflow.com/questions/34320102
复制相似问题