Skip to content

Instantly share code, notes, and snippets.

@yesez
Created June 7, 2013 18:45
Show Gist options
  • Save yesez/5731458 to your computer and use it in GitHub Desktop.
Save yesez/5731458 to your computer and use it in GitHub Desktop.
Introducción a AngularJS. Probando eventos como ng-click
var mainCtrl = function($scope, $http) {
// la función obtenerPaises pasa a ser parte del Scope para ser identificada en la Vista
$scope.obtenerPaises = function() {
$http({ method: 'GET', url: '/api/values' })
.success(function(data) {
$scope.paises = data;
})
.error(function(data) {
$scope.error = data.Message;
});
};
}
<!DOCTYPE html>
<html lang="en" data-ng-app="">
<head>
<title>Países</title>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body data-ng-controller="mainCtrl">
<ul>
<li data-ng-repeat="pais in paises">
{{ pais.Id }} - {{ pais.Nombre }}
</li>
</ul>
<!-- Cambio: botón para cargar los datos a través de la directiva ng-click -->
<button data-ng-click="obtenerPaises()">Cargar</button>
<script src="http://code.angularjs.org/1.0.6/angular.min.js"></script>
<script src="Scripts/app.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment