Error: The method $scope.weatherAPI.get is not recognized as a function

weatherApplication.controller('forecastController', ['$scope', '$http','$resource', '$routeParams', 'cityProviderService','$sce',function($scope, $http,$resource, $routeParams, cityProviderService,$sce) {

    $scope.selectedCity = cityProviderService.selectedCity;

    $scope.weatherAPIURL = $sce.trustAsResourceUrl("http://api.openweathermap.org/data/2.5/weather",{ callback: "JSON_CALLBACK" }, { get: { method: "JSONP" }} );
    
    //$scope.weatherData=$sce.valueOf($scope.weatherAPIURL);

    $scope.currentWeather= $scope.weatherAPIURL.get ({q: $scope.selectedCity,appid:'xxxxxxxxx'}); //uniqueid cannot be made public.
    console.log($scope.currentWeather);
}]);

Answer №1

If you don't want to assign a $scope variable, you can use the following code snippet instead:

$scope.getWeather = function() {
    url = "http://api.openweathermap.org/data/2.5/weather?q="+$scope.city+"&mode=json&APPID="+$scope.appId; 
    $http.get(url).then(function(response) {
        console.log(response.data);
    }, function myError(response) {
        onsole.log(response.statusText);
    });
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The AJAX request to send data to PHP is not functioning correctly

I have an issue where I am trying to send data to my server using AJAX in PHP. Even though I have set the method as POST, it seems to be executing as a GET request instead. Here is the code snippet: $.ajax({ type: 'POST', data: { user: us ...

Creating a series of text messages for Push Notifications using FCM in conjunction with Ionic 1. Multiple lines of

I've been attempting to send push notifications with multiline text messages. I've experimented with various techniques such as using setBigStyle in FCMService.java, HTML.fromHTML, and others, but haven't been successful in getting the messa ...

Tips for utilizing the ng-filter Json [@attributes] with Angularjs

I'm trying to sort through sports feed based on sport ID, but the JSON feeds are structured with @attributes. JSON Feeds series: [ { @attributes: { id: "cdf590b4-0206-45b0-9122-20eae46a2b27", name: "Pakistan tour of Sri Lanka, 2015", year ...

Unable to render the ng-repeat child scope attribute

I am working on displaying a list of data records using ng-repeat. Each data object entry (referred to as a coupon) needs to have specific properties ($scope.etabName and $scope.etabDistance) extracted from it, calculations performed, and the results displ ...

Exploring the possibilities of using AngularJS for AJAX functionality in a Ruby On Rails

I recently started learning AngularJS and Rails, and I attempted to develop a Rails application incorporating AngularJS. Currently, I am looking to make a POST request to send data and insert it into the database. In the Activity Controller: def create ...

Preserve query parameters in Laravel 5.3 when passing additional GET values

Is there a way to maintain the values passed from another route on my dashboard? Here is how the dashboard URL appears after receiving a GET request from another route: http://localhost:8000/?lat=45.328686399999995&lng=14.446922599999999 Whe ...

A beginner's guide to efficiently indexing tables in AngularJS

Having Trouble with ng-repeat Indexing <tr ng-repeat="Ward in Wardresult "> <td>{{$index + 1}}</td> ...................... some column ....................... </tr> Although, the output ...

Unable to locate the required conditional template for the 'mdRadioButton' directive due to the absence of the 'mdRadioGroup' controller

I am currently working on developing a custom directive that will help me display questions within a survey. Given the multiple types of questions I have, I decided to create a single directive and dynamically change its template based on the type of quest ...

My directive is not being loaded in Angular

Recently, I have started using Angular but encountered an issue with loading my directive. I am looking to load my directive immediately upon page load. Where should I load the data-show directive? <div class="row"> <div class="c ...

Angular does not seem to be triggering $watch for changes in arrays

Trying to activate a $watch function after a delay in Angular: Controller Information .controller('MyCtrl', ['$scope', function ($scope) { $scope.chickens = ["Jim", "Joe", "Fred"]; $scope.chickens.push("Steve"); setTimeou ...

Utilizing a filter within the ng-model directive

I have a question about using a filter with an h3 element. Here is the code snippet: {{ event.date | date:'dd-MM-yyyy' }} It's working perfectly fine and Angular is formatting the date as expected. However, when I try to use the same filte ...

Issues relating to the total count of pages in the uib-pagination component of AngularJS

While there is a previous thread discussing a similar topic Calculating total items in AngularJs Pagination (ui.bootstrap) doesn't work correctly, it does not address my specific issue and I am unsure how to contribute to it. We are using a complex s ...

Verify FileReader.onload function using Jasmine and AngularJS

I have a unique directive specifically designed for uploading and importing binary files. This directive listens for a change event on an <input type="file"../> element. Currently, I am facing an issue with the code coverage of my test. Although the ...

Navigating through angularjs is as simple as following these steps

My main directory folder is named angularjs and contains the following files: 1.index.html 2.main.html 3.blue.html 4.red.html 5.green.html I am trying to set up routing using AngularJs, but I am encountering an error. Can you help me figure out what I am ...

Retrieving ng-repeat $index with filtering in AngularJS controller

I am facing a challenge with my ng-repeat list and filter in AngularJS. I am unable to retrieve the visible $index value from inside my controller. Although I can display the index easily and see it change dynamically when the list is filtered, I am strug ...

Is there a way for me to determine if a route has been defined at the start of my AngularJS ui-router application?

My AngularJS SPA application utilizes angular-ui-router. Normally, the application starts when the user visits: (a) www.example.com and then automatically loads the index.html page. At this point, I want the application to directly transition to the home ...

Angular is having trouble with binding

What seems to be the issue in this code snippet? JSFiddle. function SecondCtrl($scope, Data) { $scope.data = Data; $scope.reversedMessage = function(message) { return message.split("").reverse().join(""); }; } ...

Designing a hybrid app navigation menu

In our development plans, we aim to design a cutting-edge hybrid mobile application by incorporating HTML, Kendo-UI, and AngularJS. One crucial component of the mobile app will be a left sidebar navigation menu featuring various items for navigating throu ...

The server is unable to receive lists that are included within the JSON object being passed in

Below are the data contracts utilized in the function. public class ResumeSkillsListDataContract : IResumeSkillsListDataContract { public IList<ISkillDataContract> KnownSkillsList { get; set; } public IList<ISkillDataContract> BadSkill ...

Can you explain the contrast between ng-init and the initialization of a controller?

There are multiple techniques to initialize a variable in Angular. One method is by using the ng-init directive: <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"> </script> <body& ...