0

这是我创建的导航 html 模块,我在获得成功响应并显示响应后显示该模块,但我无法在此处显示响应..

angular.module("nav.html", []).run(["$templateCache", function($templateCache) {
            $templateCache.put("parcials/admin/nav.tpl.html",
                "<ul class=\"nav\" data-ng-controller=\"LoginSubmit\">\n" +
                "  <li ui-route=\"/admin\" ng-class=\"{active:$uiRoute}\">\n" +
                "    <a href=\"#/admin\">\n" +
                "      <i class=\"icon-home\"></i>\n" +
                "      Admin Home\n" +
                "    </a>\n" +
                "  </li>\n" +
                "  <li><a href=\"\">Logged in as {{username}} </a></li>\n" +
                "  <li><a href=\"\">Log out</a></li>\n" +
                "</ul>");
        }]);
    Controller part
    angular.module( 'ngBoilerplate', [
        'templates-app',
        'templates-common',
        'ngBoilerplate.home',         
        'ngBoilerplate.admin',
        'ui.state',
        'ui.route'
        ])

    .config( function myAppConfig ( $stateProvider, $urlRouterProvider ) {
        $urlRouterProvider.otherwise( '/home' );
    })
    .run( function run () {
        })
    .factory('GetNavTemplate', function(){
        var navTemplate = 'parcials/nav.tpl.html';
        return {
            navTemplate: function() {
                return navTemplate;
            },
            setNavTemplate: function(newNavTemplate) {
                navTemplate = newNavTemplate;
            }
        };
    })
.controller( 'LoginSubmit', function LoginSubmit ( $scope, $http, $location, $cookies, GetNavTemplate ) {
    $scope.submit = function() {
        $http.post(angular.apiBase+'login.php', {
            username: $scope.username, 
            password: $scope.password, 
            remember: $scope.remember
            }).success(function(response){
            $scope.response =  response;
            if(typeof response == 'string' && response.indexOf("Error") !== -1){ // this is an error
                alert('test alert');
                $scope.statusMsg = "";
                $scope.errorMsg = response;
            }else{
                responseJSON = angular.fromJson(response);
                console.log(responseJSON);
                $scope.errorMsg = "";
                $scope.statusMsg = "Logged in as "+responseJSON.username;
                $location.path("/"+responseJSON.type);
                $scope.username = responseJSON.username;
                $scope.type = responseJSON.type;
                $scope.session = responseJSON.session;
                $scope.GetNavTemplate = GetNavTemplate;
                GetNavTemplate.setNavTemplate('nav.html');                       
            }
        });
    };
});

在成功的 http 响应中,我正在加载模板文件,但无法在模板文件中传递变量。任何帮助都会很棒...提前谢谢...

4

0 回答 0