Javascript 在模板中显示http响应变量

Javascript 在模板中显示http响应变量,javascript,angularjs,Javascript,Angularjs,这是我创建的nav html模块,我在获得成功响应并显示响应后正在显示该模块,但我无法在此处显示响应 angular.module("nav.html", []).run(["$templateCache", function($templateCache) { $templateCache.put("parcials/admin/nav.tpl.html", "<ul class=\"nav\" data-ng-controller

这是我创建的nav 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');                       
            }
        });
    };
});
angular.module(“nav.html”,[])。运行([“$templateCache”),函数($templateCache){
$templateCache.put(“parcials/admin/nav.tpl.html”,
“
    \n”+ “
  • \n”+ “\n”+ “
  • \n”+ “
  • \n”+ “
  • \n”+ “
”; }]); 控制器部件 角度模块('ngBoilerplate'[ “模板应用程序”, “通用模板”, “样板,家”, 'ngBoilerplate.admin', “ui.state”, “ui.route” ]) .config(函数myAppConfig($stateProvider,$urlRouterProvider){ $urlRouterProvider。否则('/home'); }) .run(函数运行(){ }) .factory('GetNavTemplate',函数(){ var navTemplate='parcials/nav.tpl.html'; 返回{ navTemplate:function(){ 返回导航模板; }, setNavTemplate:函数(newNavTemplate){ navTemplate=新建navTemplate; } }; }) .controller('LoginSubmit',函数LoginSubmit($scope,$http,$location,$cookies,GetNavTemplate){ $scope.submit=函数(){ $http.post(angular.apiBase+'login.php'{ 用户名:$scope.username, 密码:$scope.password, 记住:$scope。记住 }).成功(功能(响应){ $scope.response=响应; 如果(typeof response=='string'&&response.indexOf(“错误”)!==-1){//这是一个错误 警报(“测试警报”); $scope.statusMsg=“”; $scope.errorMsg=响应; }否则{ responseJSON=angular.fromJson(响应); console.log(responseJSON); $scope.errorMsg=“”; $scope.statusMsg=“以“+responseJSON.username”身份登录; $location.path(“/”+responseJSON.type); $scope.username=responseJSON.username; $scope.type=responseJSON.type; $scope.session=responseJSON.session; $scope.GetNavTemplate=GetNavTemplate; setNavTemplate('nav.html'); } }); }; });
在SuccessFull http响应中,我正在加载模板文件,但无法在模板文件中传递变量。。 任何帮助都会很好。。。
提前感谢……

方法似乎太复杂了。为什么不使用
ng include
?它已经开发了代码,我正在编辑代码。。