将$ location注入主控制器时,不会加载视图

时间:2016-08-03 14:44:00

标签: angularjs

以下是我的index.html文件:

<body ng-controller="MyController" ng-cloak>
    <div ng-if="isAuthenticated">
        <div ng-include="'shared/header/client.header.view.html'"></div>
        <div ng-view></div>
        <div ng-include="'shared/footer/client.footer.view.html'"></div>
    </div>
    <div class="alert alert-{{alert.type}} animated main-alert" ng-class="{'flipInY': alert.show, 'flipOutY': !alert.show, 'alert-hidden': !alert.hasBeenShown}">
        <strong>{{alert.title}}</strong>&nbsp;&nbsp;{{alert.message}}
        <br/>
        <center>
            <button data-dismiss="alert">Ok</button>
        </center>
    </div>
</body>

路线配置:

app.config(function ($routeProvider, $httpProvider) {
        $routeProvider.when("/dashboard", {
            templateUrl: "components/dashboard/client.dashboard.view.html",
        }).when("/sales", {
            templateUrl: "components/dashboard/client.sales.view.html",
            controller: "SalesController"
        }).when("/settings", {
            templateUrl: "shared/common_components/client.proxyuser.view.html"
        }).otherwise("/dashboard");
        $httpProvider.defaults.headers.common = {};
        $httpProvider.defaults.headers.post = {};
        $httpProvider.defaults.headers.put = {};
        $httpProvider.defaults.headers.patch = {};
        $httpProvider.defaults.headers.get = {};
        $httpProvider.interceptors.push('authInterceptor');
    });

控制器:

var MyController= function ($scope, $http, authtoken, alert, buyer, API_URL) { 
       //code
        }
    app.controller("MyController", MyController);

使用上面的代码,我的所有视图都将被正确呈现和显示。但是当我向买家控制器注入$ location时,只包含页眉和页脚html,但没有加载任何视图。

var MyController= function ($scope, $location, $http, authtoken, alert, buyer, API_URL) {

        //With this $location injection, no views are loaded.
        }

他们没有显示控制台日志错误。

我是否通过在控制器中添加ng-view标签而犯了任何错误?

0 个答案:

没有答案