Search code examples
angularjsng-submit

ng-submit not working for this plunk


I am new to angular js and was building my first app to display users while hitting the github API.

here's the plunk I was working on : http://plnkr.co/edit/bJxijtHV4kBmJ3heMxA9?p=preview

<form name="searchUser" ng-submit="Search(userName)">
  <input type="search" placeholder="User to find" ng-model="userName"/>
  <input type="submit" value="Search" />
</form>

Javascript code:

var app = angular.module('myApp', []);
app.controller('MainController', function($scope, $http) {
var Search = function(userName) {
$http.get('https://api.github.com/users/' + userName)
  .then(function(response) {
    $scope.person = response.data;
  });
 };
});

Please let me know where I am going wrong. This is my first app. Excuse any silly mistakes :)


Solution

  • it should be like following.

    $scope.Search = function(userName){
    //rest of the code goes here
    }