Skip to content

Instantly share code, notes, and snippets.

@jrbalsas
Last active May 4, 2018 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrbalsas/de4883bacd081f54726aa420e101d696 to your computer and use it in GitHub Desktop.
Save jrbalsas/de4883bacd081f54726aa420e101d696 to your computer and use it in GitHub Desktop.
Práctica angular
angular.module('Club',[ 'ClientesControllerModule' /*otros módulos de la APP*/ ] );
<h1> Lista de clientes</h1>
<table>
<tr><td>Nombre</td><td>DNI</td><td>Socio</td></tr>
<tr data-ng-repeat="c in $ctrl.listaclientes"
data-ng-click="$ctrl.visualiza(c)" >
<td>{{c.nombre}}</td> <td>{{c.dni}}</td>
<td>{{c.socio}}</td>
</tr>
</table>
<blockquote data-ng-show="$ctrl.cliente.nombre.length>0">
<h2>{{$ctrl.cliente.nombre}}</h2>
<p>DNI: {{$ctrl.cliente.dni}}</p>
<p>{{($ctrl.cliente.socio?’SÍ’:’NO’)}} es socio</p>
</blockquote>
class ClientesCtrl {
constructor() {
this.nombre = "Desconocido";
this.listaclientes = [
{nombre: 'Carlos', dni: '12345678T', socio: true},
{nombre: 'María', dni: '87654321G', socio: true},
{nombre: 'Juan', dni: '12121212H', socio: false}];
}
};
angular.module('ClientesControllerModule',[] )
.controller('ClientesCtrl', [ ClientesCtrl ]);
<!DOCTYPE html>
<html lang="es">
<head>
<script>
class ClientesCtrl () { //$scope no es necesario
constructor () {
this.listaclientes= [
{nombre:'Carlos', dni:'12345678T', socio:true},
{nombre:'María', dni:'87654321G', socio:true},
{nombre:'Juan', dni:'12121212H', socio:false} ];
}
};
</script>
</head>
<body data-ng-app="" data-ng-controller="ClientesCtrl as $ctrl">
<p>Hay un total de {{$ctrl.listaclientes.length}} clientes</p>
<p>{{$ctrl.listaclientes | json }}</p>
<script src="//ajax.googleapis.com/..."></script>
</body>
</html>
<body data-ng-app=""
data-ng-controller="ClientesCtrl as $ctrl">
<input data-ng-model="nombre"> {{$ctrl.nombre}}
<h1> Lista de clientes</h1>
<table>
<tr><td>Nombre</td><td>DNI</td><td>Socio</td></tr>
<tr data-ng-repeat="c in $ctrl.listaclientes">
<td>{{c.nombre}}</td> <td>{{c.dni}}</td>
<td>{{c.socio}}</td>
</tr>
</table>
…..
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment