【发布时间】:2025-12-04 11:35:01
【问题描述】:
编辑:这实际上只发生在 Google Chrome 中。
我的路线是这样设置的
@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();
}
}
任何建议都会很棒。
【问题讨论】:
-
您的
@RouteConfig()用于已弃用的路由器。您的导入也适用于旧的 Angular2 版本。 -
在
public products: Product[];中您从哪里获得了Product对象?
标签: javascript angular