Angular Papers JS

0

Well, I have not found it in any other post, if there is srry :) finally

I have the following config

myApp.config(function($routeProvider) {
    $routeProvider

        // route for the index page
        .when('/index', {
            templateUrl : 'pages/index.html',
            controller  : 'mainController'
        })

        // route for the home page
        .when('/home', {
            templateUrl : 'pages/home.html',
            controller  : 'aboutController'
        })

}); 

I just wanted to work with different views, for different users, on the same route.

For example, I have two users, user X is adm and user Y is a regular user, so when they both access the '/ index' route they will have the same view.

But when they accessed the route '/ home' wanted a different template to be shown for each one. How can I do this?

I accept all kinds of help. VALEEU!

    
asked by anonymous 21.04.2016 / 04:41

1 answer

1

You can create directives and insert them into your home.html

In the aboutController controller, you capture the session data, check if the user is logged in and put the information in $scope.usuario . You can pass it to the directive and use the object usuario there.

home.html

<div ng-if="usuario.privilegio == 'guest'">
<diretiva-para-guest usuario=usuario></diretiva-para-guest>
</div>

<div ng-if="usuario.privilegio == 'admin'">
<diretiva-para-admin usuario=usuario></diretiva-para-admin>
</div>

In the directive you call the HTMLs for each and pass the data as you like ...

directive-guest.js

app.directive('diretivaParaGuest', function() {

    return {
        restrict: 'E',
         scope: {
            usuario: '='

        },
        templateUrl: "home-guest.html",
        controller: function($scope){


          $scope.ola = "Hello Usuario" + $scope.usuario.nome;

         },
        controllerAs: 'guestController'
    };
});

directive-admin.js

app.directive('diretivaParaAdmin', function() {

    return {
        restrict: 'E',
        scope: {
        usuario: '='

    },
        templateUrl: "home-admin.html",
        controller: function($scope){


          $scope.ola = "Hello Usuario" + $scope.usuario.nome;

         },
        controllerAs: 'adminController'
    };
});
    
24.04.2016 / 19:10