范围在视图中不起作用..我的代码是否正确?是否有可能将$ scope放入这样的开关状态?

时间:2017-05-04 15:21:44

标签: angularjs

$http.get('http://localhost:8080/TestProjetJersyAngularJs/rest/LoginServices/login', config)
    .then(function(data) {
        var data = data.data;

        if (data == "Administrateur" || data == "Utilisateur") {

            switch (data) {
                case 'Administrateur':
                    alert("in case admin");
                    alert("arg 0 in case admin : " + arg0);
                    $cookieStore.put('arg0', arg0);
                    $scope.roleAdmin = data;
                    $location.path('/accueil');

                    break;
                case 'Utilisateur':
                    alert("in case user");
                    $cookieStore.put('arg0', arg0);
                    $scope.roleUser = data;
                    $location.path('/accueil');

                    break;
                default:
            }

            $scope.arg0 = $cookieStore.get('arg0');
            alert("scope arg 0 : " + $scope.arg0)
        } else if (data == "error") {
            $scope.errorMsg = "donnees incorrecte!!";
            $location.path('/');



        }

    });

1 个答案:

答案 0 :(得分:0)

   <!DOCTYPE html>
<html data-ng-app="myApp" >
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="resources/Js/angular.min.js"></script>
 <script type="text/javascript" src="resources/Js/angular-route.min.js"></script>
  <script type="text/javascript" src="resources/Js/angular-cookies.min.js"></script>
 <script type="text/javascript" src="resources/Js/Controller.js"></script>

</head>
<body>
<h1>hiiiiiiiiii angularJs</h1>
<div data-ng-controller="demoCtrl">
     Bonjour : {{arg0}} <br>
     role :{{ roleUser }} <br>
      <a href="" data-ng-click="logout()" target="_self">Log Out</a><br>
     <a href="" data-ng-click="newPage()" target="_self">newPageTest</a>
</div>
</body>
</html>