Skip to content

Instantly share code, notes, and snippets.

@porfidev
Last active June 1, 2016 01:28
Show Gist options
  • Save porfidev/5d76bc81631b99ae2c31c36a31d47155 to your computer and use it in GitHub Desktop.
Save porfidev/5d76bc81631b99ae2c31c36a31d47155 to your computer and use it in GitHub Desktop.
Curso Angular - 03.1 Práctica con Controladores
/**
* Created by elporfirio on 31/05/16.
*/
angular.module('practicapp', [])
.controller('ContenidoController', function(){
this.activo = 1;
this.activar = function(opcion){
this.activo = opcion;
}
});
<!DOCTYPE html>
<html lang="en" ng-app="practicapp">
<head>
<meta charset="UTF-8">
<title>elporfirio.com | practica angular</title>
</head>
<body ng-controller="ContenidoController as cctrl">
<button ng-click="cctrl.activar(1)">Sección 1</button>
<button ng-click="cctrl.activar(2)">Sección 2</button>
<button ng-click="cctrl.activar(3)">Sección 3</button>
{{ cctrl.activo }}
<div ng-show="cctrl.activo == 1">
<h3>Sección 1</h3>
<p>Este es el contenido de la primera</p>
</div>
<div ng-show="cctrl.activo == 2">
<h3>Sección 2</h3>
<p>Este es el contenido de la segunda</p>
</div>
<div ng-show="cctrl.activo == 3">
<h3>Sección 3</h3>
<p>Este es el contenido de la tercera</p>
</div>
<script src="js/angular.min.js"></script>
<script src="js/app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment