Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:35:21+00:00 2026-06-18T12:35:21+00:00

I’m trying to set up a little POC to see whether or not angular

  • 0

I’m trying to set up a little POC to see whether or not angular would work for something I’m in the middle of.

I set up a REST server which I am able to CRUD with via angular. However, as the documentation and tutorials out there are so all over the place (read: SUPER inconsistent), I am not sure that the behavior I’m not seeing is the result of incorrect code or it’s not something I can do like this.

I’ve gleaned from the docs that two-way binding is available, but it isn’t clear how it works. NB I’ve read dozens of articles explaining how it works at a low level a’la https://stackoverflow.com/a/9693933/2044377 but haven’t been able to answer my own question.

I have angular speaking to a REST service which modifies a sql db.

What I am wondering about and am trying to POC is if I have 2 browsers open and I change a value in the db, will it reflect in the other browser window?

As I said, I have it updating the db, but as of now it is not updating the other browser window.

app.js

angular.module('myApp', ['ngResource']);

var appMock = angular.module('appMock', ['myApp', 'ngMockE2E']);
appMock.run(function($httpBackend) {});

controllers.js

function MainCtrl($scope, $http, $resource) {
  $scope.message = "";
  $scope.fruits = [];
  $scope.fruit = {};
  $scope.view = 'partials/list.html';

  var _URL_ = '/cirest/index.php/rest/fruit';


  function _use_$resources_() { return false; }
  function _fn_error(err) {
    $scope.message = err;
  } 

  $scope.listFruits = function() {

    $scope.view = 'partials/list.html';

    var fn_success = function(data) {
        $scope.fruits = data;
    };

    $http.get(_URL_).success(fn_success).error(_fn_error);

  }


  function _fn_success_put_post(data) {
        $scope.fruit = {};
        $scope.listFruits();  
  }

  function createFruit() {
        $http.post(_URL_, $scope.fruit).success(function(data){
        $scope.listFruits()
      }).error(_fn_error);

  }


  function updateFruit() {
      $http.post(_URL_, $scope.fruit).success(_fn_success_put_post).error(_fn_error);
  }

  function deleteFruit() {

      $http.put(_URL_, $scope.fruit).success(_fn_success_put_post).error(_fn_error);

  }

 $scope.delete = function(id) {
    if (!confirm("Are you sure you want do delete the fruit?")) return; 
        $http.delete("/cirest/index.php/rest/fruit?id=" + id).success(_fn_success_put_post).error(_fn_error);

  }


  $scope.newFruit = function() {
    $scope.fruit = {};
    $scope.fruitOperation = "New fruit";
    $scope.buttonLabel = "Create";
    $scope.view = "partials/form.html";
  }

  $scope.edit = function(id) {
    $scope.fruitOperation = "Modify fruit";
    $scope.buttonLabel = "Save";

    $scope.message = "";

    var fn_success = function(data) {
        $scope.fruit = {};
        $scope.fruit.id = id;
        $scope.view = 'partials/form.html';
    };


      $http.get(_URL_ + '/' + id).success(fn_success).error(_fn_error);

  }


  $scope.save = function() {
    if ($scope.fruit.id) {
      updateFruit();
    }
    else {
      createFruit();
    }
  }

  $scope.cancel = function() {
    $scope.message = "";
    $scope.fruit = {};
    $scope.fruits = [];
    $scope.listFruits();    
  }

  $scope.listFruits();
}
MainCtrl.$inject = ['$scope', '$http', '$resource'];

list.html

{{message}}
<hr/>
   <a href="" ng-click="newFruit()">New Fruit</a>  
   <ul ng-model="listFruit">
      <li ng-repeat="fruit in fruits">
        <a href="" ng-click="edit(fruit.id)">id [{{fruit.id}}] {{fruit.name}} is {{fruit.color}}</a>
        [<a href="" ng-click="delete(fruit.id)">X</a>]
    </li>
   </ul>      

index.html

<!doctype html>
<html lang="en" ng-app="myApp">
<head>
  <meta charset="utf-8">
  <title>FRUUUUUUUUUUUUUUUUUUUUUUUUUUUIT</title>
  <link rel="stylesheet" href="css/bootstrap/css/bootstrap.css"/>
</head>
<body>
  <div class="navbar">NAVBARRRRRRRRRRR</div>
  <div class="container">
    <div class="row">
      <div ng-controller="MainCtrl">

          <button ng-click="listFruits()">ListFruit()</button>
          <button ng-click="cancel()">Cancel()</button>


                <ng-include src="view"></ng-include>          

        </div>

    </div>
  </div>


  <!-- In production use:
  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.4/angular.min.js"></script>
  -->
  <script src="lib/angular/angular.js"></script>
  <script src="lib/angular/angular-resource.js"></script>
  <script src="js/app.js"></script>
  <script src="js/services.js"></script>
  <script src="js/controllers.js"></script>
  <script src="js/filters.js"></script>
  <script src="js/directives.js"></script>
</body>
</html>

form.html

<h3>{{fruitOperation}}</h3>
<hr/>
<form name="fruitForm">
  <input type="hidden" name="" ng-model="fruit.id" />
  <p><label>name</label><input type="text" name="name" ng-model="fruit.name" value="dfgdfgdfg" required="true" /></p>
  <p><label>color</label><input type="text" name="color" ng-model="fruit.color" value="fruit.color" required="true" /></p>
  <hr/>
  <input type="submit" ng-click="save()" value="{{buttonLabel}}" /> <button ng-click="cancel()">Cancel</button>
</form>

Thanks for any insight or pointers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:35:23+00:00Added an answer on June 18, 2026 at 12:35 pm

    Two-way binding refers to changes occurring in your controller’s scope showing up in your views and vice-versa. Angular does not have any implicit knowledge of your server-side data. In order for your changes to show up in another open browser window, for example, you will need to have a notification layer which pushes changes to the client via long polling, web sockets, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.