c# - Angular 2 routing resource not found -
i using vs 2015 rc, working on webapi project , when try use routing in angular 2 following errors:
failed load resource: server responded status of 404 (not found) localhost:14580/angular2/router
potentially unhandled rejection [3] error loading "angular2/router" @ localhost:14580/angular2/router error loading "angular2/router" "components/main/main" @ localhost:14580/components/main/main.js not found: localhost:14580/angular2/router (warning: non-error used)
the view basic import of main.ts component. component code follows:
/// <reference path="../../scripts/typings/angular2/angular2.d.ts" /> /// <reference path="../../scripts/typings/_custom/ng2.d.ts" /> import {router, routeconfig, routerlink, routeroutlet} 'angular2/router'; import {component, view, bootstrap} 'angular2/angular2'; import {login} '../login/login'; import {status, json} '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 );
if bring in latest definitelytyped typings angular 2 may easier working. here working example:
http://www.syntaxsuccess.com/viewarticle/routing-in-angular-2.0
Comments
Post a Comment