Created
June 7, 2013 18:45
-
-
Save yesez/5731458 to your computer and use it in GitHub Desktop.
Introducción a AngularJS. Probando eventos como ng-click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}); | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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