Ways to showcase a single row using ng-repeat in AngularJS

Recently delving into AngularJs and integrating it into my project, I created a WebApi function that retrieves a city's current temperature. I am seeking guidance on how to display this single temperature in my HTML file. While familiar with ng-repeat for displaying multiple items, I am uncertain of the approach for displaying a single item.

Upon inspecting my current code provided below, the expected result was to showcase "20" as the temperature, unfortunately, it displays "2" and "0" in separate rows. Can someone provide assistance on achieving the desired output of "20" in a singular row?

<div ng-controller="WearherController">
    <table ng-repeat="weather in weathers" border="1">
        <tr>
            <td>{{weather}}</td>
        </tr>
    </table>
</div>
....
....
....
<script>
var app = angular.module("ZenHaberApp", []);
app.controller("WeatherController", function ($scope, $http) {
    var city = 'Adana';
    $http.get('http://localhost:62747/api/getweatherbycityname/' + city).
      success(function (data, status, headers, config) {
          $scope.weathers = data.condition_temp;

      }).
      error(function (data, status, headers, config) {
          alert("error");
      });
});
</script> 

After following @Sajeetharan's advice, there is now an unexpected image being displayed. How can I resolve this issue? What could be causing this anomaly? https://i.sstatic.net/gv1YI.png

Below is the remaining code section:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.25/angular.min.js"></script>
<script>
    var app = angular.module("ZenHaberApp", []);
    app.controller("WeatherController", function ($scope, $http) {
        var city = 'Adana';
        $http.get('http://localhost:62747/api/getweatherbycityname/' + city).
          success(function (data, status, headers, config) {
              $scope.weathers = data.condition_temp;

          }).
          error(function (data, status, headers, config) {
              alert("error");
          });
    });
</script>

SOLUTION:

Thanks to @Sajeetharan for identifying the issue. The problem lied within {{weather}}

It should have been changed to {{weathers}}

Answer №1

You have the option to directly assign the $scope variable weathers,

<table border="1">
        <tr>
            <td>{{weathers}}</td>
        </tr>
 </table>

DEMO

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

Errors occurred when trying to use Jquery to handle a JSON response

enter code here function customPaging(action, action1, page) { alert("in customPaging"); $.getJSON("./paging.do?action="+escape(action)+"&p="+escape(action1)+"&str="+escape(page), function(data){ alert("Length: "+data.length); var options = ...

Checking the parameters passed to a function in Typescript: A step-by-step guide

Currently, I am working with Typescript and then transpiling my TS code into JavaScript. However, I have encountered an issue that I am struggling to resolve. The error message I am facing is as follows: Error Found in TypeScript on Line:2 - error TS230 ...

Using Ajax and Jquery to send a variable to a PHP script

Having trouble accessing the variable from JQuery Ajax? I've tried everything, even added a cdn script tag to both files. However, I keep getting an error of undefined index. Notice: Undefined index: head in C:\xampp\htdocs\Project&bso ...

Creating a dynamic shift in background color

Is it possible to use jQuery to slowly change the color of diagonal lines in a background styled with CSS, while also adding a fading effect? I have created a fiddle with the necessary CSS to display a static background. You can view it here: http://jsfid ...

Discovering ways to access deeply nested JSON data in Vue JS

i am dealing with JSON data that includes payment information. I am facing issues retrieving the paid_amount and date for both cash_payment and installment_payment. { "response": [ { "status": "sold", "price": "1000 ...

Angular Functions and Their Application

Just starting out with Angular and facing a challenge with handling downloaded JSON data. I wrote this function: for (var i = 0; i < $scope.Objects.length; i++){ $http.get($scope.Objects[i]["Commit"]).success(function(data) { Commit = data ...

"Trouble displaying specific events based on their IDs retrieved from the MySQL database

Each button in my list is associated with a specific person. Upon clicking a button, it directs to calendar.php?id=5 (where 5 is the personal id). I want the calendar to display the vacations scheduled for that particular id from the MySQL database. even ...

Exploring nested hash maps within JavaScript

Having some trouble with creating a nested hash map in JavaScript (js), similar to the example below: let rooms = {}; rooms[roomNum][personName] = somethings; However, I keep encountering an error when attempting this: TypeError: Cannot set property &apo ...

How can a command in a test be executed that is located within a specific "section" in Nightwatch?

I've been utilizing nightwatch for my test automation. Within my page object, I have a "section" containing various commands. However, when attempting to call these commands in the test script, I encountered an error stating "section is not a function ...

Error 406 – Unacceptable Response in Spring MVC and AngularJS: What You Need to Know

HTTP Status 406 – Not Acceptable The server cannot provide a response that is acceptable to the client according to the request headers, and it does not have a default representation. sample controller code @RequestMapping(value="/welcomes", method = R ...

Tips for transferring information from a React template to a Flask API

I am exploring the use of a sign-in template, but I'm uncertain about how to send data from this template to my Flask API. I have come across information suggesting that states are only used in components. Is this factual? I attempted to call the Regi ...

Troubleshooting: Next JS 13/14 - Server component failing to update data upon revisiting without requiring a refresh

After attempting to retrieve the most recent liked items from a server component in next, I noticed that the data only displays when manually refreshing the page. Even when I navigate away and return, the data is not refetched automatically - however, usin ...

Utilizing AngularJS to dynamically compile a template and implement it within a Showdown extension

I've been working on developing a Showdown extension for my Angular app that will display scope variables. Initially, it was easy to set up to show basic scope variables, but now I'm facing an issue when trying to use the results of an ng-repeat. ...

What is the best way to trigger a refresh callback on Angular datatable pagination after updating the data

I've successfully set up my angular datatable configuration. Here's what it looks like: vm.dtOptions = DTOptionsBuilder.newOptions(). withPaginationType('full_numbers'). //withOption('ajax', { ...

The default value of the select option will not be displayed upon loading and will also not appear when another option is selected

I created a form using vue.js that includes a select option dropdown. However, the default value does not display when the form loads, and when a new option is selected from the dropdown, it also does not show. When I use v-for to loop through all options ...

Using AngularJS, swap out particular characters within a given string

I recently developed an app using a black box logic approach, complete with configurations and page building functionalities. Each of my pages is constructed using Angular components, including a confirmation pop-up message for certain actions. When it co ...

Display the Bootstrap tooltip when an Angular input field is in focus and has encountered an error

This specific example was extracted from the angularjs documentation <form name="myForm" ng-controller="Ctrl"> userType: <input name="input" ng-model="userType" required> <span class="error" ng-show="myForm.input.$error.required">Req ...

Automatically trigger a popup box to appear following an AJAX request

I am currently working on a time counter script that triggers a code execution through ajax upon completion. The result of the code should be displayed in a popup box. Below is the code snippet I am using: var ticker = function() { counter--; var t = ...

The notion of await goes beyond simply waiting for a promise to be fulfilled

Hey there everyone! I've been struggling with a problem for some time now, and I just can't seem to figure it out by simply searching online. That's why I'm turning to all of you for help. Situation: I'm working on a small applic ...

Deleting an element in an Array of objects using Typescript

export class AppComponent implements OnInit { title = 'bucketList'; bucketList: BucketListItem[] = [ new BucketListItem( "Goa Trip", "Travel to Goa" ) ]; ngOnInit() { } onItemAdded(eventData) ...