Skip to content

Instantly share code, notes, and snippets.

@rachaelshaw
Last active August 29, 2015 14:25
Show Gist options
  • Save rachaelshaw/d7e95ae7bb5f60899478 to your computer and use it in GitHub Desktop.
Save rachaelshaw/d7e95ae7bb5f60899478 to your computer and use it in GitHub Desktop.
For Mr. T

Step 1: Paste this in the <head> of layout.ejs:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script>

Step 2:

<div ng-app="Pokemon" ng-controller="PokeCtrl">
  <form ng-submit="getPokemon()">
    <label for="id">Type a number 1-150</label>
    <input type="text ng-model="pokemonId">
    <input type="submit" value="Get Pokemon">
  </form>
</div>

Step 3: Make a file called Pokemon.js and paste:

angular.module('Pokemon', []);

angular.module('Pokemon')
.controller('PokeCtrl', [
        '$scope', '$http',
function($scope, $http) {

$scope.getPokemon = function() {
 // FUNCTION HERE
};


}]);

Step 4: Paste this underneath:

<div ng-show="pokemon">
{{pokemon}}
</div>

Step 5: Paste this intead of //FUNCTION HERE

$http.post('/pokemon', {
  pokemonId: $scope.pokemonId
})
.then(function(res){
  $scope.pokemon = res.data;
});


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment