Is it possible that calling .one() and .get() in AngularJS with Restangular returns an array?

As a newcomer to JavaScript frameworks, I am currently using Angular 1.0.8 in conjunction with Restangular. I would greatly appreciate a beginner-friendly explanation for my current issue.

The HTML snippet I have is very straightforward, with an <section> element (ng-app specified in the body):

<section class="comment-list block scrollable wrapper" style="height:350px" ng-controller="MessageStreamController">
    <div> {{ message.message }} </div>
    <div class="input-group">
        <input type="text" class="form-control" ng-change="change()" ng-model="message.message" placeholder="Input your comment here">
          <span class="input-group-btn">
            <button class="btn btn-primary" type="button" ng-click="clicked()">POST</button>
          </span>
    </div>
</section>

accompanied by the following <script>

var JApp = angular.module('JApp', ['restangular']);

JApp.controller('MessageStreamController', function($scope, Restangular) {
  var service = Restangular.all('message-stream');

  $scope.clicked = function() {
    $scope.message = service.one('index', 1).get();
  }
})

The backend response from /message-stream/index/1 simply includes:

return json_encode(array(
    'message' => 'Hey there James',
    'user' => 'Terry'
));

This causes the

<div> {{ message.message }} </div>
and the input field to display 'Hey there James'. Everything functions correctly up to this point.

However, I encounter an issue where I am unable to edit the input box after it has been populated.

Several sources suggested that this problem arises when ng-repeat is not used, but I am anticipating a single JSON object from the backend.

Any guidance or suggestions on how to resolve this?

UPDATE: Switching from Restangular to $resource resolves my issue. However, I would like to understand why this occurs. Insights from individuals experienced with Restangular would be valuable.

Answer №1

Restangular always provides a promise for query results that is immutable.

To work around this limitation, it's suggested to directly assign the actual result to your scope. More details can be found in response to this inquiry - Why Inputs Cannot Be Edited in Angular.JS?

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 OTP submission in Phone Email's phone authentication using Node JS did not result in the reception of the token

I have implemented the “Login with Phone” Button from Phone Email on my Node JS website. The button opens a popup to enter the mobile number and then displays an OTP window after submission. Although I receive the OTP SMS and enter it successfully, I a ...

Unable to fetch JSON data from PHP with the help of AJAX

I seem to be encountering an issue with retrieving JSON string data from my PHP script using an AJAX call. Here are the relevant scripts: $.ajax({ type: "POST", async: false, dataType: "json", url: "databas ...

Rotating Images on Internet Explorer 8

I'm encountering an issue with rotating images in IE 8. It works flawlessly on other browsers like Chrome, Mozilla, and Firefox. Is there an alternative method for rotating images in IE 8 without using the filter progid:DXImageTransform.Microsoft.Bas ...

Accessing user input upon button press

I am facing a challenge in displaying my emailInput on my createPassword page, specifically where [email protected] is mentioned. I have provided the code snippets for both pages below, the email page containing a user input and the password page wher ...

What is the best way to incorporate a webpack bundle into another bundle?

Greetings! I am currently in the process of developing a React application with server-side rendering. The server and client segments are both written in TypeScript and transpiled separately to ensure smooth functionality. To provide you with a clearer pic ...

Enhanced subscription feature with robust data verification

My script hides the input element and displays a "thanks message" after validation of the input field called emailfield. The "thanks message" is only shown if the email field is validated. Thank you! var nextStep = document.querySelector('#nextStep ...

Linked selection options for state, city, and postal code

I have set up a cascading dropdown list - State -> City -> Pincode . Instead of fetching data from the database, I am using JSON. The dropdown functions smoothly on the local server, but experiences slowness on the web server. Here is a snippet of ...

In React Router version 4, it is stated that each router is only allowed to have a single child element when using multiple routes

I'm currently working on implementing a sidebar alongside the main content area using react-router-dom. Instead of just rendering <Sidebar/> directly, I want to pass it the location prop due to another issue where clicking a <Link/> in the ...

Items in Collection+JSON that are connected to items in another collection

Currently, I am developing a REST web server using nodejs and considering implementing it with Collection+JSON as the hypermedia type. I'm unsure if Collection+JSON supports representing 1 to n relationships within a collection. If I have a collectio ...

Facing a dilemma: Javascript not updating HTML image source

I am facing an issue while attempting to modify the source of my HTML image element. Despite using document.getElementId('image') in my code, I am unable to make it work as intended. Surprisingly, there are no errors displayed. Interestingly, whe ...

Employing square brackets for accessing JSON data in JavaScript

I am facing a requirement where I need to extract the value of the JSON data based on the column specified by the user. for (var k = 0; k < arr.length; k++) { for (var i = 0; i < checkedFilters.length; i++) { console.log("value[columnNam ...

Switch the background color alternately from red to green every second

Need help with a webpage that changes the background color every second using JavaScript. The issue lies in figuring out how to correctly change the variable within the function. Here's an example of the code: <!DOCTYPE html> <html> ...

Anticipated request for spy navigation with path '/members' was expected, but unfortunately was not triggered

I am facing an issue with a service method that performs an HTTP delete operation. The expected behavior is that upon successful deletion, the page should be redirected to another location. However, during testing, I noticed that the router navigation func ...

NextJS rewrites work seamlessly in a live environment

I recently implemented a method to rewrite requests to my backend server during development: https://nextjs.org/docs/api-reference/next.config.js/rewrites rewrites: async () => [ ...nextI18NextRewrites(localeSubpaths), { source: '/api/:path*' ...

An option instead of using a pop-up window

Currently, I have a PHP script and a small form that allows users to upload image files. The user can access this feature by clicking on a button on the parent HTML page, which opens up a Pop Up Window. I understand that not everyone is a fan of 'Pop ...

Access the angular controller using the radio button option

I am looking to showcase data in an HTML table retrieved from an Angular controller. I have the controller set up but I am unsure about how to display the data when a radio button is selected. <div class="radio"> <label class="radio-inline" ...

Removing an element from an array in JavaScript: A step-by-step guide

I've been struggling with this error for the past couple of hours. Currently, I'm in the process of developing an idle game centered around building your own city. The issue arises when I attempt to delete a building from the build queue array. E ...

add a hyperlink within a mouse click action

Looking for a way to make phone numbers clickable on mobile devices? Check out this script! I've implemented a script that displays a phone number when users click 'call us' and sends a Google Analytics event. However, I'm having troub ...

Angular - the art of linking Observables together to merge their outcomes

I need to execute two requests consecutively and merge their results at the end. If the response body of the first request contains isSuccessful = false, then the second request should not be executed. If the first request fails for any reason, the second ...

Is storing text in data-content and utilizing bootstrap-popover.js compatible?

Is it possible to display HTML content in a popover using ? How reliable is it to store text in data-content? Can we expect it to function properly across all browsers? ...