【发布时间】:2015-12-20 12:09:12
【问题描述】:
我期待开发一个 AngularJS 应用程序,我想知道是否可以使用单个控制器发送多个 $http.get 请求,每次发送到不同的 URL,具体取决于调用的模板。
例子:
App.js
.state('app.grocery', {
url: '/grocery',
views: {
'menuContent': {
templateUrl: 'templates/grocery.html',
controller: 'MasterCtrl'
}
}
})
.state('app.beverages', {
url: '/beverages',
views: {
'menuContent': {
templateUrl: 'templates/beverages.html',
controller: 'MasterCtrl'
}
}
})
在我的 Controller.js 中,我希望首先捕获被调用的 templateURL 并基于该设置 $http.get URL。假设如果 templateURL 是 templates/grocery.html,则 $http.get URL 将是“ xyz.com/grocery.json”,如果 templateURL 是 templates/beverages.html,则 $http.get URL 将是“xyz.com/beverages.json”
【问题讨论】: