【发布时间】:2016-10-20 00:28:18
【问题描述】:
在我的 angularJS 应用程序中,我使用 symfony 作为 rest API。
根据我当前的 url,我是否使用 app_dev.php 下的 $http。 我通过以下代码实现了这一点:
app.run (function( $rootScope, $location ){
$rootScope.dev = "";
if ( $location.absUrl().search("app_dev.php") > 0 ) {
$rootScope.dev = "app_dev.php/";
}
}
app.controller('OfferIndexCtrl', function($scope, $http, $location, $filter, $rootScope){
$http.get( $rootScope.dev + 'stage/offer/get').success(function(json){
$scope.offerList = json.offerList;
});
}
这很好用。但是 .run() 在 .config() 之后运行,并且无法将其集成到 routeProvider 中。
谁能帮我把它集成到我的 routeProvider 中
app.config(['$routeProvider', '$locationProvider',
function( $routeProvider, $locationProvider ){
$routeProvider.
when('/', {
templateUrl: 'stage/view/offer/index',
controller: 'OfferIndexCtrl'
}).
otherwise({
redirectTo: '/'
})
}
]);
【问题讨论】:
标签: javascript angularjs rest symfony route-provider