0

我有一个模板和一个控制器。每当状态更改为相应的视图时,控制器中都会执行一些代码。如何确保在控制器完成执行之前没有渲染模板的任何组件。我已经知道解决 - 在这个问题中回答的承诺 -

使用 ng-controller 时延迟模板加载

我正在寻找的是一种将模板渲染推迟到我的控制器完成它的工作的方法。我也知道 ng-cloak,但是当我将它应用于模板的根元素时它不起作用。我可能对它有错误的理解。

这是代码 -

<div class="container">
    <div class="row">
        <div class="col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 text-center animated fadeInDown">
            <h3>Welcome to ***********</h3>

            <p>No authentication found. This may be because you are logged out.
            </p>

            <p>Please click the following button to authenticate you using portal.</p>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 text-center animated fadeInDown">
            <br/>
            <a class="btn btn-primary" target="_self"
               href="/portal/oauth/authorize?client_id=cms-web-view&response_type=token&redirect_uri={{returnToUri}}">Authenticate
            </a>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-8 col-xs-offset-2 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 text-center animated fadeInDown">
            <br/>
            <p class="m-t">
                <small> © 2015</small>
            </p>
        </div>
    </div>
</div>-->

和控制器 -

define(['layout/module'], function (module) {

    'use strict';

    module.registerController('AuthCtrl', function($scope, $location, $state, $log, $http, $window) {

        $scope.returnToUri = $location.absUrl();

        var hash = $location.hash();
        $log.info($location.absUrl());
        if(hash.indexOf('access_token') > -1) {
            var extractRegex = /access_token=([a-zA-Z0-9-]*)&/;
            var result = extractRegex.exec(hash);
            if(result.length > 1) {
                $log.debug('Found access token in hash, redirecting to the app.', result[1]);
                localStorage.setItem('oauthToken', result[1]);
                $http.defaults.headers.common.Authorization = 'Bearer ' + result[1];
                $state.go('app.dashboard');
            } else {
                $log.error('access_token not extractable via regex from hash', hash);
            }
        } else if(hash.length > 0) {
            $log.debug('Hash didn\'t contain the access_token', hash);
        }

        // Circular redirection - An intermediate page is necessary
        //$window.location.href = '/portal/oauth/authorize?client_id=cms-web-view&response_type=token&redirect_uri=' + $location.absUrl();
    });
});
4

0 回答 0