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;
});