Lau*_*ate 2 c# typescript visual-studio-2015 angular
我正在使用VS 2015 RC,在WebAPI项目上工作,当我尝试在Angular 2中使用路由时,我收到以下错误:
无法加载资源:服务器响应状态为404(未找到)localhost:14580/angular2/router
潜在的未处理拒绝[3]在localhost上加载"angular2/router"时出错:14580/angular2/router在localhost上从"Components/main/main"加载"angular2/router"时出错:14580/Components/main/main.js Not Found :localhost:14580/angular2/router(警告:使用非错误)
视图是main.ts组件的基本导入.组件代码如下:
/// <reference path="../../Scripts/typings/angular2/angular2.d.ts" />
/// <reference path="../../Scripts/typings/_custom/ng2.d.ts" />
import {Router, RouteConfig, RouterLink, RouterOutlet} from 'angular2/router';
import {Component, View, bootstrap} from 'angular2/angular2';
import {Login} from '../login/login';
import {status, json} from 'Scripts/utils/fetch'
// Annotation section
@Component({
selector: 'my-app'
})
@View({
templateUrl: 'Views/main/main.html',
directives: [RouterLink, RouterOutlet]
})
@RouteConfig([
{ path: '/login', as: 'login', component: Login }
])
// Component controller
export class Main {
//router: Router;
name: string;
constructor(router: Router) {
//this.router = router;
this.name = 'Routing';
router.config([{ path: '/login', as: 'login', component: Login }]);
}
login(event, email, password) {
event.preventDefault();
window.fetch('/api/Account/Login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
email, password
})
})
.then(status)
.then(json)
.then((response) => {
alert(response);
// this.router.parent.navigate('/home');
})
.catch((error) => {
alert(error.message);
console.log(error.message);
});
}
}
bootstrap(
Main
);
Run Code Online (Sandbox Code Playgroud)
adl*_*lr0 17
你需要以router.dev.js与你所包含的方式相同的方式包含在html中angular2.dev.js.所以只需将此行添加到您index.html的头部:
<script src="../node_modules/angular2/bundles/router.dev.js"></script>
Run Code Online (Sandbox Code Playgroud)
PS.我知道你已经解决了这个问题,但答案并不明确,我花了一些时间才意识到我的应用程序出了什么问题.
| 归档时间: |
|
| 查看次数: |
7640 次 |
| 最近记录: |