【发布时间】:2014-07-18 10:20:44
【问题描述】:
我在我的 Angular 应用程序中使用 $routeProvider 进行路由。对于 2 条路线,我使用相同的 HTML 模板和相同的控制器。
when('/products, {
templateUrl: 'views/products.html',
controller: 'ProductListCtrl'
}).
when('/myProducts', {
templateUrl: 'views/products.html',
controller: 'ProductListCtrl'
}).
只有我想显示的数据差异。 IE。对于路径products,我希望AJAX 请求发送到myserver:8080/products,对于路径myProducts,我想将AJAX 请求中的数据加载到myserver:8080/products/my。
现在我使用$location 服务来区分当前页面(products 或myProducts)并加载适当的数据。
有更优雅的方法吗?比如使用$routeProvider的resolve方法?
【问题讨论】:
标签: javascript ajax angularjs