1

Here is my code :

http://jsfiddle.net/n8t2born/1/

there are 3 js files , and it works pretty much good when I use static URL (without inputCity variable inside) . How should I tell angular correctly to take that info from my input and put it into the link and show weather info for a particular city ?

This is my form:

    <form class="form-container" ng-submit="Weather.getWeather(inputCity)">
        <input class="input-field" type="text" ng-model="inputCity" placeholder="City">
        <input class="button-style" type="submit" value="Show Weather">
    </form>

and it is my angular.factory:

angular
.module('weather.factory', [])
.factory('Weather', [
    '$http',
    function($http) {
        return {
            getWeather : function(inputCity) {
                return $http({
                    url: 'http://api.wunderground.com/api/KEY/conditions/q/' + inputCity + '.json',
                    method: 'GET'
                })
            }
        }
    }
]);
2
  • 1
    The way this question is written, it is likely to attract downvotes and/or close votes. In order for a question to be on topic for the site, you need to provide a Minimal, Complete, Verifiable Example in the question itself. see stackoverflow.com/help/mcve and How to Ask Commented Mar 29, 2015 at 17:05
  • 1
    and got an answer, instead of a closure :) Commented Mar 29, 2015 at 17:37

1 Answer 1

1

You should never call you service method from your controller which has promise, It should call from controller & then update you required location data in ajax sucess

HTML

<form class="form-container" ng-submit="submitForm(inputCity)">
    <input class="input-field" type="text" ng-model="inputCity" placeholder="City">
    <input class="button-style" type="submit" value="Show Weather">
</form>

Code

$scope.submitForm =function(inputCity){
   Weather.getWeather(inputCity).success(function(){
      //data updation will lie here
   }).error(function(error){
      //do error handling here
   })
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.