Javascript 应用程序仅在Angular 2中的某些页面设置为默认页面时中断(仅限Chrome)
编辑:这实际上只发生在谷歌浏览器中 我的路线是这样安排的Javascript 应用程序仅在Angular 2中的某些页面设置为默认页面时中断(仅限Chrome),javascript,angular,Javascript,Angular,编辑:这实际上只发生在谷歌浏览器中 我的路线是这样安排的 @RouteConfig([ {path:'/login', name: 'Login', component: LoginComponent}, {path:'/products', name: 'Products', component: ProductComponent,useAsDefault:true}, {path:'/register', name
@RouteConfig([
{path:'/login', name: 'Login', component: LoginComponent},
{path:'/products', name: 'Products', component: ProductComponent,useAsDefault:true},
{path:'/register', name: 'Register', component: RegisterComponent},
{path:'/checkout', name: 'Checkout', component: CheckoutComponent},
{path:'/movie/:id', name: 'View', component: ViewmovieComponent},
{path:'/profile/', name: 'Profile', component: ProfileComponent}
])
当将/products设置为默认页面时,整个应用程序似乎会无声地失败。但是,如果我将另一个页面设置为主页,则它可以完美地工作(包括产品页面)
我没有在控制台中看到任何错误消息,因此无法确定如何调试该问题。我的产品组件如下所示
import {Component} from 'angular2/core';
import {ProductService} from './product.service';
import {OnInit} from 'angular2/core';
import {ROUTER_DIRECTIVES} from 'angular2/router';
@Component({
selector : 'product',
templateUrl : './templates/product.tpl.html',
directives: [ROUTER_DIRECTIVES]
})
export class ProductComponent implements OnInit {
public products: Product[];
constructor(private _productService: ProductService){
console.log('fired');
}
//////////
letsGo() {
$('html,body').animate({
scrollTop: $('.movies').offset().top - 45
});
}
getProducts(){
this._productService.getProducts()
.subscribe(
data => this.products = data.message,
error => console.log(error);
);
}
ngOnInit():any{
this.getProducts();
}
}
任何建议都很好。您是否尝试从
/
重定向到您的产品组件,而不是设置路由默认值?也许这样行
例:
])您是否尝试从
/
重定向到您的产品组件,而不是设置路由默认值?也许这样行
例:
])我在初始化注入实例时看到了错误:从未报告。我猜你的产品和服务有问题。我会深入研究它,要么放入console.log()语句查看它到达的位置,要么在
try{…}catch(e){console.error(e);}中包围每个函数体(包括构造函数和从构造函数执行的任何代码)
我在初始化注入实例时看到了错误:无法报告。我猜你的产品和服务有问题。我会深入研究它,要么放入console.log()语句查看它到达的位置,要么在try{…}catch(e){console.error(e);}
中围绕每个函数体(包括构造函数和从构造函数执行的任何代码),您的@RouteConfig()
是针对不推荐使用的路由器的。您的导入也适用于旧的Angular2版本从何处获得产品
对象?您的@RouteConfig()
是针对不推荐使用的路由器的。您的导入也适用于旧的Angular2版本代码>从何处获得产品
对象?尝试过,但结果相同!你还在使用“旧”路由器吗?尝试合并到新版本?仍然使用旧版本(虽然我直到上面的一些评论才意识到这一点),如果我不能让它工作,我会尝试合并到新版本。然而,考虑到它适用于每一个其他页面,显然有些事情是可以修复的。我无法解释这个问题,因为我对angular的经验不足。但你似乎也在使用angular2的旧版本。您是否尝试过将组件复制粘贴到另一个文件中或为其指定另一个组件名称?尝试过,但结果相同!你还在使用“旧”路由器吗?尝试合并到新版本?仍然使用旧版本(虽然我直到上面的一些评论才意识到这一点),如果我不能让它工作,我会尝试合并到新版本。然而,考虑到它适用于每一个其他页面,显然有些事情是可以修复的。我无法解释这个问题,因为我对angular的经验不足。但你似乎也在使用angular2的旧版本。您是否尝试过将组件复制粘贴到另一个文件中或为其指定另一个组件名称?
@RouteConfig([
{path:'', redirectTo: '/products', pathMatch: 'full'},
{path:'/login', name: 'Login', component: LoginComponent},
{path:'/products', name: 'Products', component: ProductComponent},
{path:'/register', name: 'Register', component: RegisterComponent},
{path:'/checkout', name: 'Checkout', component: CheckoutComponent},
{path:'/movie/:id', name: 'View', component: ViewmovieComponent},
{path:'/profile/', name: 'Profile', component: ProfileComponent}