Чтобы достичь ожидаемого результата, используйте нижеприведенную опцию
1. Завершение возврата фабрики в другую функцию, передавая cityName
2. Используйте значение $ scope.name в качестве значения параметра, т.е. getWeatherJSON ($ scope.cityName)
Быстрый способ выполнения запроса GET.
Фабрика:
app.factory("getWeatherJSON", ['$http', function ($http) {
return function(cityName){
return $http.get(<code>https://api.openweathermap.org/data/2.5/weather? q=:cityName&appid=8c644b89f214d6bee6c2123faabfb05&units=metric
)
}}]);
Контроллер:
app.controller("mainController", ["$scope", "getWeatherJSON", function mainController($scope, getWeatherJSON) {
$scope.cityName = "Rio de Janeiro";
getWeatherJSON($scope.cityName).then(function (data) {
const weatherData = data.data;
console.log(weatherData)
})
}])