0

I have some config that route to different views. It is hardcoded for now. There is var "a" and ifit equals to 1 it redirected to view1. But i want to set there $http and to route according to result.

How could i insert $http inside config?

This is my js:

angular.module('mainPage', [
'mainPage.controllers',
'ngRoute','kendo.directives'
]);

angular.module('mainPage').config(function ($routeProvider) {
  //Here i want to put my $http.

    var a = 1;
    if(a==1){
        $routeProvider.otherwise({ redirectTo: '/view1' });

    }else{
     bbb   
    }
    $routeProvider.when('/view1', {
        controller: 'Controller1',
        templateUrl: 'partials/validation.html'
    }).when('/view2', {
        controller: 'Controller2',
        templateUrl: 'partials/guests.html'
    });
});

angular.module('mainPage', [])

.controller('Controller1',function($scope){

    $scope.source = [
        {nav_id:1,nav_name:"Validation",nav_src:"validation"},
        {nav_id:2,nav_name:"Guests",nav_src:"guests"}
    ];

})
.controller('Controller2',function($scope){
    $scope.now=new Date();
});

and this is my html:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <style>html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.common.min.css" />
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.default.min.css" />
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.min.css" />
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.dataviz.default.min.css" />
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1411/styles/kendo.mobile.all.min.css" />

    <script src="http://cdn.kendostatic.com/2014.3.1411/js/jquery.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.3.1411/js/angular.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.3.1411/js/kendo.all.min.js"></script>

</head>
<body>
<div   ng-app="mainPage" ng-controller="MainCtrl">

    <ng-view></ng-view>
 </div>
    <script src="js/angular-route.js"></script>
    <script src="js/main_page.js"></script>
</body>
</html>

I want to put something like this:

$http({/
        url: 'aaa/aaa/aaa',
        method: "GET",
        headers: { 'Content-Type': 'application/json' }
    }).success(function (data, status, headers, config) {

        }
    }).error(function (data, status, headers, config) {

    });

1 Answer 1

0

You can't inject into config, but for sure put this stuff into the 'run' block.

app.run(function($http) {
     // use $http
})

how to inject dependency into module.config(configFn) in angular

Sign up to request clarification or add additional context in comments.

2 Comments

But config is bootstrapped before run. I need $http and then config
Well, you can't. Config is for providers only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.