Angular2 路由未被 requirejs 加载
Angular2 Routing is not being loaded by requirejs
您好,我一直在学习教程并且更改了一些文件夹结构,一切都很好。
在 Alpha 阶段我使用了包含路由的 angular2-seed 项目。
我现在正在尝试设置路由,但我总是无法加载导出。
这个组件位于 /app/template/footer,我相信导入应该可以,我也尝试在导入前添加一个斜杠或者相对地添加 2 或 3 次../
import {Component} from 'angular2/core';
import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from 'angular2/router';
@Component({
selector: 'navigation',
directives: [ROUTER_DIRECTIVES],
template: `
<ul>
<li> <a [routerLink]="['./orders']">Orders</a></li>
</ul>
`
})
export class Navigation {
}
控制台错误:
1 未捕获的语法错误:意外的标记 <
2 未捕获的语法错误:意外的标记 <
正在评估 http://localhost:3000/angular2/router
加载错误 http://localhost:3000/app/boot.js
响应仅加载 index.html
您是否在 index.js
文件中添加了以下内容:
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
如果是这样,您应该检查 SystemJS 和 Typescript 编译器的配置。事实上,SystemJS 提供了模块支持(导入模块和注册模块)。
你是这样配置SystemJs的吗:
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
关于tsconfig.json
文件中Typescript编译器的配置:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
您还可以查看 Angular2 快速入门以获取更多详细信息:https://angular.io/guide/quickstart。
希望对你有帮助,
蒂埃里
您好,我一直在学习教程并且更改了一些文件夹结构,一切都很好。
在 Alpha 阶段我使用了包含路由的 angular2-seed 项目。
我现在正在尝试设置路由,但我总是无法加载导出。
这个组件位于 /app/template/footer,我相信导入应该可以,我也尝试在导入前添加一个斜杠或者相对地添加 2 或 3 次../
import {Component} from 'angular2/core';
import {ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig} from 'angular2/router';
@Component({
selector: 'navigation',
directives: [ROUTER_DIRECTIVES],
template: `
<ul>
<li> <a [routerLink]="['./orders']">Orders</a></li>
</ul>
`
})
export class Navigation {
}
控制台错误:
1 未捕获的语法错误:意外的标记 < 2 未捕获的语法错误:意外的标记 < 正在评估 http://localhost:3000/angular2/router 加载错误 http://localhost:3000/app/boot.js
响应仅加载 index.html
您是否在 index.js
文件中添加了以下内容:
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="node_modules/angular2/bundles/router.dev.js"></script>
如果是这样,您应该检查 SystemJS 和 Typescript 编译器的配置。事实上,SystemJS 提供了模块支持(导入模块和注册模块)。
你是这样配置SystemJs的吗:
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
关于tsconfig.json
文件中Typescript编译器的配置:
{
"compilerOptions": {
"target": "ES5",
"module": "system",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules"
]
}
您还可以查看 Angular2 快速入门以获取更多详细信息:https://angular.io/guide/quickstart。
希望对你有帮助, 蒂埃里