Как динамически изменять содержимое в ng-include templete в angularjs - PullRequest
0 голосов
/ 10 апреля 2020

У меня есть этот код. Я пытаюсь динамически изменять меню после входа пользователя с помощью электронной почты и пароля. После успешного входа в систему ответом будет список меню из серверной части, и я хочу изменить список меню в заголовке. html, который включен динамически с ответом.

index. html

 <body ng-controller="homeController">
        <div class="container-fluid" >
            <div class="card text-center">
                <ng-include src="'jsp/header.jsp'"></ng-include>
                <div ng-view></div>
            </div >
        </div>
  </body>

логин. html

<div class="card-body" >
    <form ng-submit="sign_in()">
      <div class="form-group">
        <label for="exampleInputEmail1">Email address</label>
        <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="Enter email" ng-model="email_id" required="required" >
        <small id="emailHelp" class="form-text text-muted"></small>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">Password</label>
        <input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password" ng-model="pwd" required="required">
      </div>
      <div class="form-group form-check">
        <input type="checkbox" class="form-check-input" id="exampleCheck1">
        <label class="form-check-label" for="exampleCheck1">Check me out</label>
      </div>
      <button type="submit" class="btn btn-primary" >Submit</button>
    </form>
</div>

header. html

<div class="card-header">
<ul class="nav nav-pills card-header-pills" >
    <li class="nav-item" ng-repeat="(key,value) in menu">
        <a class="nav-link" href="{{value}}">{{key}}</a>
    </li>
 </ul>

script

    <script type="text/javascript">
    var app = angular.module('sample', ['ngRoute']); 
    app.config(['$routeProvider',function($routeProvider){
        $routeProvider.when('/login',{
            templateUrl : 'jsp/login.jsp',
            controller : 'loginController'
        }).when('/Register',{
            templateUrl : 'jsp/Register.jsp'
        }).when('/home',{
            templateUrl : 'jsp/header.jsp'
        }).otherwise({
            redirectTo : '' 
        });
    }]);
    app.controller("homeController",['$scope','$http',function($scope,$http){
        $scope.menu = {"Home" : "#","Login" : "#/login","Register" : "#/Register"};
    }]);

    app.controller("loginController",['$scope','$http',function($scope,$http){
        $scope.email_id = "";
        $scope.pwd = "";
        $scope.menu = {};
        $scope.sign_in = function(){
            $http.get("login.do?mode=login&user="+$scope.email_id+"&pwd="+$scope.pwd).success(function(response){
                $scope.menu = response;
                console.log($scope.menu);
            });
        }

    }]);
  </script>
...