Different content according to url, angularjs [closed]

0

I would like to know what is called or how the functionality is done, by means of the url controlling the content, for example something like facebook, which manages the profile from the url: www.facebook.com/perfil.persona and in base to profile.person shows you all that information.

I would like to implement it on a website that I have with angularjs spa.

    
asked by Mau 21.04.2017 в 23:14
source

1 answer

0

Are you looking for something like this?

var app = angular.module('app', ['ngRoute']);
app.config(function($routeProvider) {
    $routeProvider

        .when('/', {
            templateUrl : 'home.html',
            controller  : 'mainController'
        })

        .when('/about', {
            templateUrl : 'about.html',
            controller  : 'aboutController'
        })

        .when('/contact/:id', {
            templateUrl : 'contact.html',
            controller  : 'contactController'
        });
});

app.controller('mainController', function($scope) {
});

app.controller('aboutController', function($scope) {
});

app.controller('contactController', ['$scope', '$routeParams',
   function ($scope, $routeParams) {
     //Obtenés un id desde la URL
     var currentId = $routeParams.id;
}]);

From the html, you can navigate like this:

  <ul class="nav navbar-nav navbar-right">
    <li><a href="#"> Home</a></li>
    <li><a href="#about">About</a></li>
    <!-- En este link podés pasar el id que necesites -->
    <li><a href="#contact/1">Contact</a></li>
  </ul>

I hope it serves you. Greetings

    
answered by 21.04.2017 / 23:59
source