从URL角度删除#并重新加载问题

时间:2018-10-26 06:09:24

标签: angularjs node.js

在我的应用程序中,我设置了$ locationProvider.html5Mode(true); 和nodejs在这里设置

app.get('*', function(req, res){
res.sendfile(path.join(__dirname, 'public/index.html'));

});

页面刷新后,将index.html页面内容返回到我的rootController中 在rootController内部,我有api调用,但它返回的索引页面内容是这样的

<!DOCTYPE html>\r\n<html ng-app='sTrack' style=\"max-width: 100%;\r\noverflow-x: hidden;\">\r\n<head>\r\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">\r\n  <title>\r\n   sTrack\r\n </title>\r\n <base href='/'></base>\r\n <link rel=\"shortcut icon\" href=\"/favicon.ico\" />\r\n <script type=\"application/javascript\" src=\"/javascripts/common/jquery/jquery.min.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/jquery/jquery-ui.min.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/angular-1-5-7.min.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/angular-route.min.js\"></script>\r\n <script src=\"/javascripts/common/angular-ui-router.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/bootstrap.min.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/angucomplete-alt.min.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/FileSaver.min.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/autocomplete.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/checklist-model.js\"></script>\r\n <script type=\"application/javascript\" src=\"/javascripts/common/ng-password-strength.min.js\"></script>\r\n\r\n <script src=\"/javascripts/common/angular-animate.min.js\"></script>\r\n <link rel=\"stylesheet\" href=\"/stylesheets/angular-material.min.css\">\r\n\r\n <script type=\"application/javascript\" src=\"/javascripts/common/jquery/jquery.min.js\">

这是我的rootController代码

app.controller('rootCtrl', ['$scope','$http','$rootScope', '$state','$window','userService', 'toastr','identityService', function ($scope,$http, $rootScope, $state,$window,userService, toastr,identityService) {

       $rootScope.username='guest';
        $rootScope.refresh=function(){
            $rootScope.roles=undefined;
            $http.get('/getRole').success(function(response){
                $rootScope.roles=response;

            })
            .error(function(err){
            toastr.error('Something Went wrong Try again later', 'Error');
            })
        }
       $rootScope.refresh();
        var isActive=identityService.getCurrentUser();
        if(isActive){

            $rootScope.showlogin=true;
            userService.getUserDataById(isActive._id).success(function(user){ //i to call want api when reload every time
                console.log('user:-'+JSON.stringify(user));
                $rootScope.username=user.username;
            }).error(function(err){
              toastr.error('Something Went wrong Try again later', 'Error');  
            })

        }

重新加载后如何调用api调用?请任何人帮助我

0 个答案:

没有答案