gourab gourab - 3 months ago 39
HTTP Question

Angularjs - user input in controller

I want to use a user input value in to controller. for example i want to take a URL and send a HTTP GET request. I have tried the following format , unfortunatly it does not work.

var app = angular.module('myApp',[]);
app.controller('myCtrl' , function($scope, $http){


Here is the url retrieved from a user's input

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {

  $scope.callAPI = function() {
      .success(function(response) {
        $scope.result = response.data;

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
  Enter url :
  <input type="text" ng-model="url" />
  <input type="submit" ng-click="callAPI()" />
  <div ng-bind="result"></div>

Note : This will show an error if you entered a wrong url